码迷,mamicode.com
首页 > 编程语言 > 详细

IntelliJ IDEA 2017版 spring-boot2.0.2 搭建 JPA springboot DataSource JPA sort排序方法使用方式, 添加关联表的 order by

时间:2018-10-26 15:06:43      阅读:497      评论:0      收藏:0      [点我收藏+]

标签:none   src   code   print   isp   listorder   spl   origin   pre   

1、sort可以直接添加在命名格式的字段中

技术分享图片
1 List<BomMain> findAllByDeleted(Integer deleted, Sort sort);
View Code

2、可以作为pageable的一个参数使用

技术分享图片
1 Page<Originals> selectBomSeriesList(Pageable pageable);
View Code

向sort传参的方式

1、装入Pageable使用

技术分享图片
1 Sort sort = new Sort(Sort.Direction.ASC, "serieName");
2 
3         Pageable pageable = PageRequest.of(0, 10, sort);
4 
5         Page<Originals> list = bomSeriesRepository.selectBomSeriesList(pageable);
6 
7         System.out.println(list.getTotalPages());
View Code

2、自行使用

技术分享图片
1 Sort sort = new Sort(Sort.Direction.ASC, "sequence");
2 
3         List<BomMain> bomMainList = bomMainRepository.findAllByDeleted(1, sort);
4 
5         log.info("列表" + gson.toJson(bomMainList));
View Code

3、多个条件表关联使用

技术分享图片
 1   List<Sort.Order> listOrder = new ArrayList<>();
 2 
 3         listOrder.add(new Sort.Order(Sort.Direction.ASC, "bomMain.sequence"));
 4 
 5         listOrder.add(new Sort.Order(Sort.Direction.ASC, "sequence"));
 6 
 7         Sort sort = Sort.by(listOrder);
 8 
 9         List<BomSub> bomSubList = bomSubRepository.findAllByDeletedAndBomMainMainId(1, "1", sort);
10 
11         log.info("列表" + gson.toJson(bomSubList));
View Code

生成SQL

技术分享图片
 1 SELECT
 2     bomsub0_.subId AS subId1_9_,
 3     bomsub0_.mainId AS mainId8_9_,
 4     bomsub0_.deleted AS deleted2_9_,
 5     bomsub0_.engName AS engName3_9_,
 6     bomsub0_.fullName AS fullName4_9_,
 7     bomsub0_.isOnShelf AS isOnShel5_9_,
 8     bomsub0_.sequence AS sequence6_9_,
 9     bomsub0_.subName AS subName7_9_ 
10 FROM
11     bomsub bomsub0_
12     LEFT OUTER JOIN bommain bommain1_ ON bomsub0_.mainId = bommain1_.mainId 
13 WHERE
14     bomsub0_.deleted =? 
15     AND bommain1_.mainId =? 
16 ORDER BY
17     bommain1_.sequence ASC,
18     bomsub0_.sequence ASC
View Code

 

IntelliJ IDEA 2017版 spring-boot2.0.2 搭建 JPA springboot DataSource JPA sort排序方法使用方式, 添加关联表的 order by

标签:none   src   code   print   isp   listorder   spl   origin   pre   

原文地址:https://www.cnblogs.com/liuyangfirst/p/9856254.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!