public Page<PostListDto> getRecentPosts(int page, int size){
        Pageable pageable = PageRequest.of(page, size, Sort.by("createTime").descending());
        Page<Post> posts = postRepository.findAll(pageable);

        return posts.map(postDtoService::convertToPostListDto);
        // 이 부분에 대한 설명 필요.

    }

이런식으로 page객체를 반환하는 service를 만들었다.

그런데 막상 response body를 받아보니

content에 아무런 정보가 없었다.

 

페이지 번호 확인

Spring Data JPA에서 페이지 번호는 0부터 시작합니다. 만약 클라이언트 측에서 페이지 번호를 1부터 시작하는 값으로 요청하고 있다면, 이는 실제로 두 번째 페이지를 요청하는 것과 같습니다. 이 때문에 데이터가 적어 첫 페이지를 넘어서면 content가 비어 있을 수 있습니다.

 

테스트 결과 페이지 1부터 시작해서 그런거였다...

+ Recent posts