我正在尝试使用JPA规范获取特定于某个范围的订单。
请查看以下代码和我的域类。日期类型来自Joda-Time,但无法与该日期匹配。
public static Specification<BnvOrder> byStatusChangedDateRange(String statusName, String fromDate, String toDate) {
DateTimeFormatter format = DateTimeFormat.forPattern("YYYY-MM-dd");
LocalDateTime fromDateTime = format.parseLocalDateTime(fromDate);
// LocalDateTime toDateTime = format.parseLocalDateTime(toDate+" 00:00:00");
return new Specification<BnvOrder>() {
@Override
public Predicate toPredicate(Root<BnvOrder> root, CriteriaQuery<?> query, CriteriaBuilder cb) {
// return cb.and(cb.lessThanOrEqualTo(root.<LocalDateTime>get(statusName), fromDateTime),
// cb.greaterThanOrEqualTo(root.<LocalDateTime>get(statusName), toDateTime));
// cb.greaterThanOrEqualTo("DATE("+root.get("deliveryEndDate")+")", fromDateTime);
return cb.between(root.get("deliveryEndDate"),fromDateTime,fromDateTime);
}
};
}