Pageable pageable = PageRequest.of(page, size, sort);
@GetMapping("/products")
public Page<ProductResponseDto> getProducts(
@RequestParam("page") int page,
@RequestParam("size") int size,
@RequestParam("sortBy") String sortBy,
@RequestParam("isAsc") boolean isAsc,
@AuthenticationPrincipal UserDetailsImpl userDetails) {
}
현재 페이지를 @RequestParam으로 넘겨줌
PostController.java
@GetMapping("/slice")
public Slice<PostResponseDto> getPostSlice(@RequestParam("page") int page) {
return postService.getPostSlice(page);
}
PostServiceImpl.java
@Override
public Slice<PostResponseDto> getPostSlice(int page) {
Sort sort = Sort.by(Sort.Direction.DESC, "modifiedAt");
Pageable pageable = PageRequest.of(page, PAGE_SIZE, sort);
Slice<Post> postSlice = postRepository.findAllBy(pageable);
Slice<PostResponseDto> postResponseDtoSlice = postSlice.map(PostResponseDto::new);
return postResponseDtoSlice;
}
PostRepository.java
Slice<Post> findAllBy(Pageable pageable);
(참고 : https://zayson.tistory.com/entry/Spring-Data-JPA%EC%9D%98-Page%EC%99%80-Slice
https://devjem.tistory.com/74
https://velog.io/@dltkdgns3435/SpringBoot-Spring-Data-JPA-%EC%97%90%EC%84%9C-Page%EC%99%80-Slice)
덕분에 좋은 정보 얻어갑니다, 감사합니다.