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

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

1 List<BomMain> findAllByDeleted(Integer deleted, Sort sort);

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

1 Page<Originals> selectBomSeriesList(Pageable pageable);

向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());

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));

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));

生成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

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

时间: 2024-07-29 15:55:20

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

Spring Boot2.0自定义配置文件使用

声明: spring boot 1.5 以后,ConfigurationProperties取消locations属性,因此采用PropertySource注解配合使用 根据Spring Boot2.0官方文档,PropertySource注解,只支持properties文件,因此排除 YAML配置 针对二,可考虑新建配置类,自行搜索,不再此次讨论范围 具体使用: 1.根目录下新建自定义配置文件夹与properties配置文件 example.name=tom example.wife=jerr

Spring Boot2.0之 监控管理

Spring boot监控中心: 针对微服务的服务状态,服务器的内存变化(内存.线程.日志管理等)检测服务配置连接地址是否有用(有些懒加载的情况下,用的时候发现卧槽不能用)模拟访问,懒加载.统计有多少个bean(Spring 容器中的bean).统计Spring MVC 中@RequestMapping(统计接口数) Actuator监控应用(无界面,返回json格式) AdminUi底层使用Actuator监控应用,实现可视化界面 Actuator是spring boot的一个附加功能,可帮助

Myeclipse下使用Maven搭建spring boot2.0项目

现在需要搭建spring boot框架,并实现一个HelloWorld的项目,让程序真正运行起来. 一.在pom.xml中引入spring-boot-start-parent,spring官方的叫stater poms,它可以提供dependency management,也就是依赖管理,引入以后在声明其它dependency的时候就不需要version了. <parent> <groupId>org.springframework.boot</groupId> <

IntelliJ IDEA 2017版 spring-boot2.0.4+mybatis+Redis处理高并发,穿透问题

一.当采用reddis缓存的时候,如果同时,一万次访问,那么就会有10000次访问数据库所以就会对数据库造成巨大压力,这时候,就要用到线程 1.方法体上加锁(优点,防护住了并发锁,缺点降低了内存效率) 1 /** 2 * 最简洁的高并发处理,但是,牺牲效率大 3 * 4 * @return 5 */ 6 public synchronized List<Student> selectAllStudent1() { 7 8 // 字符串序列化器 9 RedisSerializer redisSe

IntelliJ IDEA 2017版 spring-boot 2.0.5 邮件发送简单实例 (三)

一.搭建SpringBoot项目 详见此文:https://www.cnblogs.com/liuyangfirst/p/8298588.html 注意: 需要添加mail依赖的包,同时还添加了lombock,方便日志打印.如图所示 二.启动Application,测试项目搭建是否成功 三.配置properties文档 1 #########邮箱协议 2 spring.mail.host=smtp.163.com ####还可以是smtp.126.com 等 3 ##########发送邮件的用

IntelliJ IDEA 2017版 spring-boot2.0.4的集成JSP

一.必须依赖四个包,其中三个是springboot自带包,可以不写版本号,有一个不在springboot中,需要设置版本号 1 <!--引入Spring Boot内嵌的Tomcat对Jsp的解析包--> 2 <dependency> 3 <groupId>org.apache.tomcat.embed</groupId> 4 <artifactId>tomcat-embed-jasper</artifactId> 5 </dep

IntelliJ IDEA 2017版 spring-boot2.0.4+mybatis反向工程;mybatis+springboot逆向工程

一.搭建环境 采用IDE自动建立项目方式 然后,next next,配置导入依赖包 项目就生成了,在项目下导入配置文件GeneratorMapper.xml(项目结构如图所示) 配置文档,建立数据库和数据库连接 1 <?xml version="1.0" encoding="UTF-8"?> <!DOCTYPE generatorConfiguration PUBLIC 2 "-//mybatis.org//DTD MyBatis Gen

IntelliJ IDEA 2017版 spring-boot2.0.2 自动配置Condition

描述: 编译器修改参数      -Dfile.encoding=GBK     -Dstr.encoding=GBK Condition位置: 某一个类或注解存在的时候,装配,否则不装配 相关代码: https://github.com/liushaoye/quick_start/tree/third 原文地址:https://www.cnblogs.com/liuyangfirst/p/9069410.html

IntelliJ IDEA 2017版 spring-boot2.0.4的yml配置使用

一.必须配置字端两个 1 server: 2 port: 8080 3 servlet: 4 context-path: /demo 二.两种mvc转换springboot,一种是注解,一种就是.yml或properties配置 三.实际项目源码 https://github.com/liushaoye/sprinboot-yml/tree/master 原文地址:https://www.cnblogs.com/liuyangfirst/p/9276229.html