스프링 JPA는 페이지 처리와 정렬을 api에서 지원
Pageable pageable = PageRequest.of(0,10);
Page<Memo> result = memoRepository.findAll(pageable);
PageRequest.of(페이지,10개씩)
result.getTotalPages() -> 총 몇 페이지
result.getTotalElements() -> 전체 갯수
result.getNumber() -> 현재 페이지 번호 0부터 시작
result.getSize() -> 페이지당 데이터 갯수
result.hasNext() -> 다음 페이지가 존재 하는가
result.isFirst() -> 현재 페이지인가
마지막 파라미터에 sort추가 가능
@Documented
@Retention(RetentionPolicy.RUNTIME)
@Target(ElementType.PARAMETER)
public @interface PageableDefault {
/**
* Alias for {@link #size()}. Prefer to use the {@link #size()} method as it makes the annotation declaration more
* expressive and you'll probably want to configure the {@link #page()} anyway.
*
* @return
*/
int value() default 10;
/**
* The default-size the injected {@link org.springframework.data.domain.Pageable} should get if no corresponding
* parameter defined in request (default is 10).
*/
int size() default 10;
/**
* The default-pagenumber the injected {@link org.springframework.data.domain.Pageable} should get if no corresponding
* parameter defined in request (default is 0).
*/
int page() default 0;
/**
* The properties to sort by by default. If unset, no sorting will be applied at all.
*
* @return
*/
String[] sort() default {};
/**
* The direction to sort by. Defaults to {@link Direction#ASC}.
*
* @return
*/
Direction direction() default Direction.ASC;
value() = size()에 대한 별칭
page() = 현재 페이지
size() = 한 페이지에 노출할 데이터 건수