Spring&Spring Boot
(Spring)(Pageable) Page 객체의 구현체 PageImpl의 커스터 마이징
Developer RyanKim
2019. 6. 18. 21:14
@JsonIgnoreProperties(value = {"pageable", "last", "totalPages", "totalElements", "size", "number", "first", "numberOfElements", "sort", "empty"})
public class CustomPageImpl<T> extends PageImpl<T> {
@JsonCreator
public CustomPageImpl(List content, Pageable pageable, long total) {
super(content,pageable.getSort().isSorted() ? pageable : PageRequest.of(pageable.getPageNumber(), pageable.getPageSize(), Sort.by("createdAt").descending()), total);
}
@JsonCreator
public CustomPageImpl(List content) {
super(content);
}
@JsonGetter(value = "contents")
@Override
public List getContent() {
return super.getContent();
}
@JsonGetter(value = "paging")
public Map getPaging() {
Map<String, Object> paging = new HashMap<>();
paging.put("totalPages", super.getTotalPages());
paging.put("totalElements", super.getTotalElements());
paging.put("pageSize", super.getSize());
paging.put("pageNumber", super.getNumber() + 1);
paging.put("isFirst", super.isFirst());
paging.put("isLast", super.isLast());
paging.put("sort", super.getSort());
paging.put("isEmpty", super.isEmpty());
return paging;
}
}
---------------------------------------------------------
우리 프로젝트에 맞추기위해 커스터마이징하여 사용