Notice
Recent Posts
Recent Comments
Link
«   2024/11   »
1 2
3 4 5 6 7 8 9
10 11 12 13 14 15 16
17 18 19 20 21 22 23
24 25 26 27 28 29 30
Archives
Today
Total
관리 메뉴

개발자되기 프로젝트

JPQL 페이징 API 본문

인프런/[인프런] 자바ORM 표준 JPA 프로그래밍

JPQL 페이징 API

Seung__ 2021. 8. 16. 12:46

1. 페이징 API


  • JPA는 페이징을 다음 두 API로 추상화
    • setFirstResult(int startPosition) : 조회 시작 위치, 어디서부터?
      (0부터 시작)
    • setMaxResult(int maxResult) : 조회할 데이터 수 , 몇개?

 

 

2. 예시


  • setFirstResult(2) --> offset 적용
  • 97부터 10개
         for(int i = 0; i < 100 ; i++){
                Member member =  new Member();
                member.setAge(i);
                member.setUsername("member" + i);
                em.persist(member);
            }
            
            em.flush();
            em.clear();

            List<Member> resultList = em.createQuery("select m from Member m order by m.age desc", Member.class)
                    .setFirstResult(2).setMaxResults(10)
                    .getResultList();

            System.out.println("resultList.size() = " + resultList.size());
            for (Member member1 : resultList) {
                System.out.println("member1.toString() = " + member1.toString());
            }
resultList.size() = 10
member1.toString() = Member{id=98, username='member97', age=97}
member1.toString() = Member{id=97, username='member96', age=96}
member1.toString() = Member{id=96, username='member95', age=95}
member1.toString() = Member{id=95, username='member94', age=94}
member1.toString() = Member{id=94, username='member93', age=93}
member1.toString() = Member{id=93, username='member92', age=92}
member1.toString() = Member{id=92, username='member91', age=91}
member1.toString() = Member{id=91, username='member90', age=90}
member1.toString() = Member{id=90, username='member89', age=89}
member1.toString() = Member{id=89, username='member88', age=88}

 

JPA가 DATA BASE  DIALECT에 따라 자동으로 번역해줌.

 

 

3. GitHub : 210816 paging api


 

GitHub - bsh6463/JPQL_STUDY

Contribute to bsh6463/JPQL_STUDY development by creating an account on GitHub.

github.com

 

'인프런 > [인프런] 자바ORM 표준 JPA 프로그래밍' 카테고리의 다른 글

서브쿼리  (0) 2021.08.16
JPQL JOIN  (0) 2021.08.16
JPQL 프로젝션  (0) 2021.08.16
JPQL 기본 문법과 기능  (0) 2021.08.15
객체지향 쿼리 언어  (0) 2021.08.14
Comments