Open BananMoon opened 4 months ago
fetch()
fetchOne()
NonUniqueResultException
fetchFirst()
.limit().fetchOne()
fetchResults()
fetchCount()
.orderBy() 내에 정렬하고자 하는 필드와 그 뒤에 .desc(), .asc()를 체이닝한다.
.orderBy()
.desc()
.asc()
.nullsLast()
.nullsFirst()
조회 건수를 제한하기 위해 .offset()과 .limit()을 이용할 수 있다.
.offset()
.limit()
queryFactory.selectFrom(member) .orderBy(member.username.desc().nullsLast()) .offset(1) .limit(5) .fetchResults() // total count 쿼리가 추가 실행됨.
기본 결과 조회 방법 5가지
fetch()
: 리스트 조회. 데이터 없다면 empty list 반환.fetchOne()
: 단건 조회.NonUniqueResultException
발생fetchFirst()
:.limit().fetchOne()
여러 결과중 1개 pick.fetchResults()
: total count 쿼리 추가 실행되며, 페이징 정보가 포함됨. (**성능 주의)fetchCount()
: count 쿼리가 수행됨.정렬
.orderBy()
내에 정렬하고자 하는 필드와 그 뒤에.desc()
,.asc()
를 체이닝한다..nullsLast()
,.nullsFirst()
를 체이닝한다.페이징
조회 건수를 제한하기 위해
.offset()
과.limit()
을 이용할 수 있다..offset()
: 시작 인덱스. 최소 인덱스는 0.limit()
: 시작 인덱스로부터 조회할 갯수