Spring Data JPA 多属性排序
程序员文章站
2022-03-02 15:39:01
...
参考https://segmentfault.com/a/1190000000412105
参考http://blog.csdn.net/qq_23660243/article/details/43371969
public class WatchPoint {
private Section section;// 区间
private String rangeMileage;里程
}
public class Section{
private Railway railway;//线路
}
public class Railway {
private Railway railway;//线路
private String name;//名称
}
import org.springframework.data.domain.Sort;
import org.springframework.data.domain.Sort.Direction;
import org.springframework.data.domain.Sort.Order;
public void test(){
//按线路降序和里程升序排序
Sort sort = new Sort(Sort.Direction.DESC, "section.railway.name").and(new Sort(Sort.Direction.ASC, "rangeMileage"));
//按线路降序和里程升序排序
Order nameOrder = new Order(Direction.DESC, "section.railway.name");
Order rangeOrder = new Order(Direction.ASC, "rangeMileage");
List<Order> orders = new ArrayList<Order>();
orders.add(nameOrder);//先按线路降序
orders.add(rangeOrder);//再按里程升序
Sort sort2 = new Sort(orders);
//按线路升序和里程升序排序
Sort sort = new Sort(Direction.fromString("asc"), "section.railway.name", "rangeMileage");
}
推荐阅读
-
spring data jpa碰到的坑
-
Spring boot工具类静态属性注入及多环境配置详解
-
使用Spring Data JPA进行数据分页与排序
-
spring-data-jpa实现增删改查以及分页操作方法
-
详解Spring Data JPA使用@Query注解(Using @Query)
-
Spring Data JPA使用Sort进行排序(Using Sort)
-
详解Spring Data JPA系列之投影(Projection)的用法
-
spring data jpa使用详解(推荐)
-
javaweb各种框架组合案例(六):springboot+spring data jpa(hibernate)+restful
-
Spring-Data-JPA整合MySQL和配置的方法