1. 精确到某一天
if(geReqMain.getInputDate()!=null){
list.add(cb.equal(root.<Date> get("inputDate"), geReqMain.getInputDate()));
}
2.时间段查询
传入一个开始时间(beginDate)以及结束时间(endDate)与某个时间(someTime)进行比较:
restrictions = criteriaBuilder.and(restrictions, criteriaBuilder.greaterThanOrEqualTo(root.<Date> get("someTime"), beginDate));
restrictions = criteriaBuilder.and(restrictions, criteriaBuilder.lessThanOrEqualTo(root.<Date> get("someTime"), endDate));
其实就是两个方法不一样:大于用greaterThanOrEqualTo(...)和小于用lessThanOrEqualTo(...)
if (invoiceCreateStart != null) {
predicateList.add(criteriaBuilder.greaterThanOrEqualTo(root.get("firstInsert").as(Date.class), invoiceCreateStart));
}
if (invoiceCreateEnd != null) {
predicateList.add(criteriaBuilder.lessThanOrEqualTo(root.get("firstInsert").as(Date.class), invoiceCreateEnd));
}
模糊查
springJpa关于Date查询
最新推荐文章于 2023-06-05 15:33:32 发布
本文详细探讨了在Spring JPA中如何进行日期查询,包括使用@Temporal注解处理日期类型,利用Criteria API和Specification进行复杂日期过滤,以及在Repository接口中定义自定义日期查询方法。通过实例代码和解析,帮助开发者掌握Spring JPA日期查询的最佳实践。

最低0.47元/天 解锁文章

770

被折叠的 条评论
为什么被折叠?



