Spring Data Rest - Sort by multiple properties

前端 未结 2 743
眼角桃花
眼角桃花 2020-12-12 17:43

I have an entity as below

Class Person{
String id;
String name;
String numberOfHands;
}

With Spring Data Rest (Gosling Release Train), I\'m

2条回答
  •  忘掉有多难
    2020-12-12 18:33

    Here is how to construct the multi Sort object manually/programatically.

    Sort sort = Sort.by(
        Sort.Order.asc("name"),
        Sort.Order.desc("numberOfHands"));
    return personRepository.findAll(sort);
    

    Note: This solution does not directly solve the original question asked, but may help visitors that landed on this question while searching for a solution how to sort on multiple properties from a backend perspective / in a somewhat "hardcoded" way. (this solution does not require/take any URI parameters)

提交回复
热议问题