SPRING/JPA

[JPA] Pagaeable 다중 sort 방법

기록중.. 2021. 10. 26. 15:38

[JPA] Pagaeable 다중 sort 방법


Pagaeable 한개의 sort

@PageableDefault(size = 10, sort = "semester", direction = Sort.Direction.ASC) Pageable pageable

설명) @PageableDefault() 안에 sort="sort할 변수 명" direction = "오름차순, 내림차선 설정"

Pagaeable 다중 sort

 @PageableDefault(size = 10) @SortDefault.SortDefaults(
                    { @SortDefault(sort = "semester", direction = Sort.Direction.ASC)
                    , @SortDefault(sort = "courseNm", direction = Sort.Direction.ASC) }
            ) Pageable pageable)

설명) @PageableDefault() 다음에 @SortDefault.SortDefaults({})를 선언하여 ({}) 안에
정렬할 (Entity 안)변수명 순으로 @SortDefault()를 선언하면 된다