【发布时间】:2016-01-23 22:18:39
【问题描述】:
我正在将 Spring Data JPA 与 Spring Data REST 一起使用,并且我为我的 Thing 实体创建了一个 JpaRepository。
@Repository
public interface ThingRepository extends JpaRepository<Thing, Long> {
@RestResource(path = "findByName", rel = "findByName")
Page findByName(@Param("name") String name, Pageable page);
}
我想应用排序。我想根据自定义评级算法对Thing 列表进行排序。
List<Thing> sortByRating(List<Thing> things){
// custom logic
return things;
};
如果可能的话,我希望使用自定义函数来对结果进行排序。 Spring JPA 中这种事情的最佳方法是什么?如何让我的存储库使用我的函数对结果集进行排序?
【问题讨论】:
标签: java spring jpa spring-data spring-data-jpa