Skip to content

Commit

Permalink
[Week9][Chap4] Feat: 스프링 데이터 JPA 페이징과 정렬 - DTO 변환 (#106)
Browse files Browse the repository at this point in the history
  • Loading branch information
jyjyjy25 committed Nov 21, 2023
1 parent cb3445a commit e83ae9a
Showing 1 changed file with 1 addition and 6 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -185,18 +185,13 @@ public void paging() {

// when
Page<Member> page = memberRepository.findByAge(age, pageRequest);
Page<MemberDto> dtoPage = page.map(m -> new MemberDto(m.getId(), m.getUsername(), null));

// 페이지 계산 공식 적용
// totalPage = totalCount / size

// then
List<Member> content = page.getContent();
long totelElements = page.getTotalElements(); // totalCount랑 동일한 메서드

for (Member member : content) {
System.out.println("member = " + member);
}
System.out.println("totelElements = " + totelElements);

assertThat(content.size()).isEqualTo(3); // 조회된 데이터 수
assertThat(page.getTotalElements()).isEqualTo(5); // 총 데이터 수
Expand Down

0 comments on commit e83ae9a

Please sign in to comment.