复杂查询
@Override public JSONResult<PageResult<OrdOfflineOrderVO>> findOfflineOrder(OrdOfflineOrderSearchVO vo) { Page<OrdOfflineOrderPO> page= ordOfflineOrderRepository.findAll(new Specification<OrdOfflineOrderPO>() { @Override public Predicate toPredicate(Root<OrdOfflineOrderPO> root, CriteriaQuery<?> criteriaQuery, CriteriaBuilder criteriaBuilder) { List<Predicate> list = new ArrayList<Predicate>(); if(StringUtils.isNotBlank(vo.getProductName())){ list.add(criteriaBuilder.like(root.get("productName").as(String.class), "%"+vo.getProductName()+"%")); } if (vo.getStartTime()!=null) { //大于或等于传入时间 list.add(criteriaBuilder.greaterThanOrEqualTo(root.get("createTimestamp").as(Date.class), vo.getStartTime())); } if (vo.getEndTime()!=null) { //小于或等于传入时间 list.add(criteriaBuilder.lessThanOrEqualTo(root.get("createTimestamp").as(Date.class), vo.getEndTime())); } Predicate[] predicates = new Predicate[list.size()]; return criteriaBuilder.and(list.toArray(predicates)); } },vo.toPageRequest()); List<OrdOfflineOrderVO> list=new ArrayList<>(); page.getContent().forEach(po->{ OrdOfflineOrderVO orderVO=new OrdOfflineOrderVO(); BeanUtils.copyProperties(po,orderVO); list.add(orderVO); }); PageResult<OrdOfflineOrderVO> result = PageResult.of(page.getNumber(), page.getTotalPages(), page.getTotalElements(), list); return new JSONResult(result); }