JPA 에서 상위 N개만 찾기

zioo·2023년 2월 18일
0

Spring boot JPA 에서
Repository.findAll() 으로 전체 조회하다가 상위 N개만 찾고 싶을 때는 아주 간단하다.

쓰는 방법

findTopNByOrderByColumnNameDesc()
  • 상위 N개 조회
  • ColumnName 기준으로 정렬

예시

Repository에
List<TagCount> findTop10ByOrderByTagCountDesc(); 추가

Service에
tagCountRepository.findTop10ByOrderByTagCountDesc();

  • 예시에서는 TagCount 기준으로 상위 10개 출력

0개의 댓글