@Override
public Page<Order> findAll(String outTradeNo, String tradeNo, String mchAppid, String status, String payType,
String startData, String endData, Pageable pageable) {
Page<Order> pageList = orderDao.findAll((root,query,cb) -> {
List<Predicate> list = new ArrayList<Predicate>(); SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd");
SimpleDateFormat sdfmat = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
DateTimeFormatter df = DateTimeFormatter.ofPattern("yyyy-MM-dd HH:mm:ss");
if (StringUtils.isNotEmpty(startData) && StringUtils.isNotEmpty(endData)) {
try {
list.add(cb.between(root.get("payTime"),
LocalDateTime.parse(sdfmat.format(sdf.parse(startData)),df),
LocalDateTime.parse(sdfmat.format(sdf.parse(endData).getTime()+86400000), df)));
} catch (ParseException e) {
e.printStackTrace();
}
}
if(outTradeNo!=null && outTradeNo!="") {
list.add(cb.like(root.get("outTradeNo"), "%"+outTradeNo+"%"));
}
if(tradeNo!=null && tradeNo!="") {
list.add(cb.like(root.get("tradeNo"), "%"+tradeNo+"%"));
}
if(mchAppid!=null && mchAppid!="") {
list.add(cb.like(root.get("mchAppid"), "%"+mchAppid+"%"));
}
if(status!=null && status!="") {
list.add(cb.equal(root.get("state"), status));
}
if(payType!=null && payType!="") {
list.add(cb.equal(root.get("payType"), payType));
}
Predicate[] array = new Predicate[list.size()];
return cb.and(list.toArray(array));
}, pageable); return pageList;
}

更多精彩文章欢迎关注公众号“Java之康庄大道”

JPA条件查询时间区间用LocalDateTime的问题的更多相关文章

  1. Jpa条件查询组合查询and 和 or同时用

    条件查询,各个条件之间是and并且&&关系,其中地理信息省市区县,例如河北省,要包括其下属所有城市,每个城市包括下属区县,只选择河北省时候,要查询的是河北省所有的,他们之间是or 或者 ...

  2. Spring Data JPA 条件查询的关键字

    Spring Data JPA 为此提供了一些表达条件查询的关键字,大致如下: And --- 等价于 SQL 中的 and 关键字,比如 findByUsernameAndPassword(Stri ...

  3. SpringBoot JPA + 分页 + 单元测试SpringBoot JPA条件查询

    application.properties 新增数据库链接必须的参数 spring.jpa.properties.hibernate.hbm2ddl.auto=update 表示会自动更新表结构,所 ...

  4. Spring data jpa 条件查询-按时间段查询

    项目开发中的代码片段,仅供参考 @Override public Page<泛型> findRecordList(int couponDetailId, int pageNum, int ...

  5. mybatis的mapper特殊字符转移以及动态SQL条件查询

    前言 我们知道在项目开发中之前使用数据库查询,都是基于jdbc,进行连接查询,然后是高级一点jdbcTemplate进行查询,但是我们发现还是不是很方便,有大量重复sql语句,与代码偶合,效率低下,于 ...

  6. JPA分页查询与条件分页查询

    情有独钟的JPA 平时在写一些小项目时,比较喜欢引用 Spring Data Jpa,其实还是图他写代码快~在日常的开发工作中,分页列表查询基本是随处可见,下面一起看一下如何使用 jpa 进行多条件查 ...

  7. spring data jpa实现多条件查询(分页和不分页)

    目前的spring data jpa已经帮我们干了CRUD的大部分活了,但如果有些活它干不了(CrudRepository接口中没定义),那么只能由我们自己干了.这里要说的就是在它的框架里,如何实现自 ...

  8. 【JPA】表达条件查询的关键字

    1.通过解析方法名创建查询 框架在进行方法名解析时,会先把方法名多余的前缀截取掉,比如 find.findBy.read.readBy.get.getBy,然后对剩下部分进行解析.并且如果方法的最后一 ...

  9. Spring Data JPA,一种动态条件查询的写法

    我们在使用SpringData JPA框架时,进行条件查询,如果是固定条件的查询,我们可以使用符合框架规则的自定义方法以及@Query注解实现. 如果是查询条件是动态的,框架也提供了查询接口. Jpa ...

随机推荐

  1. web页面相关的一些常见可用字符介绍——张鑫旭

    by zhangxinxu from http://www.zhangxinxu.com本文地址:http://www.zhangxinxu.com/wordpress/?p=1623 正文开始之前先 ...

  2. 虚拟主机服务器php fsockopen函数被禁用的解决方法

    为了服务器安全考虑很多主机商禁用了php的fsockopen函数,昨天进博客,使用cos-html-cache生成静态文件,尼玛提示: Warning: fsockopen() has been di ...

  3. dynamics 365 AI 解决方案 —— 介绍

    Digital transformation has been reshaping our world and artificial intelligence (AI) is one of the n ...

  4. 使用 RamMap 清理内存 How to Use RamMap to Empty System Working Set

    使用 RamMap 清理内存 In this post I want to introduce RamMap by Microsoft. It’s a free tool you can use to ...

  5. linux系统下安装ssl证书(tomcat)

    1.申请ssl证书 2.下载ssl证书 打开此网址  https://myssl.com/cert_convert.html 将证书文件(xxx.com.crt)和密钥文件上传(xxx.com.key ...

  6. B/S与C/S架构、B/S架构协议

    软件有三大类型 单机类型.CS类型(Outlook.QQ.大型游戏).BS类型 BS结构中的协议 在BS结构中,首先使用到DNS协议:网络传输部分使用TCP/IP参考模型,其中网络接入层没有相应协议, ...

  7. 6.Spring MVC SSM整合问题总结

    1.Cannot find class [org.springframework.http.converter.json.MappingJacksonHttpMessageConverter] for ...

  8. ALTER 语句总结

    一.基础语句 ALTER TABLE 语句 ALTER TABLE 语句用于在现有表中添加.删除或修改列. <!--若要向表中添加列,请使用以下语法:--> ALTER TABLE tab ...

  9. Windows2003系统取消关机提示的方法

    方法有两种:1.编辑组策略 打开“开始”-“运行”,在“打开”一栏中输入“gpedit.msc”命令打开组策略编辑器,依次展开“计算机配置”→“管理模板”→“系统”,双击右侧窗口出现的“显示‘关闭事件 ...

  10. eclipse工具的安装配置

    安装环境 系统:Windows7 软件:jre-8u73-windows-x64.exe,eclipse-inst-win64.exe Eclipse的安装过程 1.安装jre-8u73-window ...