Change default sort order for Spring Data findAll() method

后端 未结 4 1351
一整个雨季
一整个雨季 2020-12-15 18:25

I\'m using Spring Data JPA and I wonder if it is possible to change the default sort order for a entity being used by the Spring Data findAll() method?

4条回答
  •  太阳男子
    2020-12-15 19:10

    Use a PagingAndSortingRepository instead. With that in place you can add a queryparameter ?sort=,

    Repository:

    public interface UserRepository extends PagingAndSortingRepository {
      //no custom code needed
    }
    

    GET Request:

    localhost:8080/users?sort=name,desc
    

提交回复
热议问题