cb是重写了方法中的参数CriteriaBuilder,root是参数Root
predicates.add(cb.between(root.<Date>get("createTime"),time1,time2));
方法代码:
public Page<UserPointsOrder> pageList(final GridReq req) {
Page<UserPointsOrder> page = userPointsOrderDao.findAll(new Specification<UserPointsOrder>() {
@Override
public Predicate toPredicate(Root<UserPointsOrder> root, CriteriaQuery<?> query, CriteriaBuilder cb) {
List<Predicate> predicates = new ArrayList<>();
query.orderBy(cb.desc(root.<Long> get("guid")));
long userId = StringUtils.isEmpty(req.getKeys()) ? 0 : NumberUtils.toLong(req.getKeys().trim());
if (userId > 0)
predicates.add(cb.equal(root.<Long> get("userId"), userId));
if ((req.getOther() != null && req.getOther().has("startTime"))&&
(req.getOther() != null && req.getOther().has("endTime"))) {
String startTime = req.getOther().get("startTime").toString();
Date time1 = TimeUtil.parseDate(startTime,"yyyy-MM-dd HH:mm:ss");
String endTime = req.getOther().get("endTime").toString();
Date time2 = TimeUtil.parseDate(endTime,"yyyy-MM-dd HH:mm:ss");
predicates.add(cb.between(root.<Date>get("createTime"),time1,time2));
}
return cb.and(predicates.toArray(new Predicate[predicates.size()]));
}
}, new PageRequest(req.getPage() - 1, req.getRows()));
return page;
}
largeQ
慕田峪7331174
相关分类