@SpringBootTest
@Transactional
public class QuerydslBasicTest {
@Test
public void paging1() {
List<Member> result = queryFactory
.selectFrom(member)
.orderBy(member.username.desc())
// 0부터 시작(zero index)
.offset(1)
// 최대 2건 조회
.limit(2)
.fetch();
assertThat(result.size()).isEqualTo(2);
}
}
@SpringBootTest
@Transactional
public class QuerydslBasicTest {
@Test
public void paging2() {
QueryResults<Member> queryResults = queryFactory
.selectFrom(member)
.orderBy(member.username.desc())
.offset(1)
.limit(2)
.fetchResults();
assertThat(queryResults.getTotal()).isEqualTo(4);
assertThat(queryResults.getLimit()).isEqualTo(2);
assertThat(queryResults.getOffset()).isEqualTo(1);
assertThat(queryResults.getResults().size()).isEqualTo(2);
}
}