【spring data jpa】根据一个时间字段 查询 时间段的处理方法

处理方法  包含结束时间00.00.00

         Date createDate = boxCodeLog.getCreateDate();
                if (createDate != null){
                    LocalDate localDate=createDate.toInstant().atZone(ZoneId.systemDefault()).toLocalDate();
                    localDate = localDate.plusDays(1);
                    Date endDate = java.sql.Date.valueOf(localDate);
                    predicates.add(cb.between(root.get("createDate"),createDate,endDate));
                }

 

包含结束时间 23.59.59

         Date createDate = receipt.getCreateDate();
                if (createDate != null){
                    LocalDate localDate=createDate.toInstant().atZone(ZoneId.systemDefault()).toLocalDate();
                    localDate = localDate.plusDays(1);
                    Date endDate = new Date(java.sql.Date.valueOf(localDate).getTime()-1L);
                    predicates.add(cb.between(root.get("createDate"),createDate,endDate));
                }

 

你可能感兴趣的:(【spring data jpa】根据一个时间字段 查询 时间段的处理方法)