gistfile1.txt public List serach(String serach, String stime, String etime) { List resultList = null; Specification querySpecifi = new Specification () { @Override public Predicate toPredicate(Root root, CriteriaQuery criteriaQuery, Criteri
public List serach(String serach, String stime, String etime) { List resultList = null; Specification querySpecifi = new Specification () { @Override public Predicate toPredicate(Root root, CriteriaQuery criteriaQuery, CriteriaBuilder cb) { Listpredicates = new ArrayList<>(); if (StringUtils.isNotBlank(stime)) { //大于或等于传入时间 predicates.add(cb.greaterThanOrEqualTo(root.get("commitTime").as(String.class), stime)); } if (StringUtils.isNotBlank(etime)) { //小于或等于传入时间 predicates.add(cb.lessThanOrEqualTo(root.get("commitTime").as(String.class), etime)); } if (StringUtils.isNotBlank(serach)) { //模糊查找 predicates.add(cb.like(root.get("name").as(String.class), "%" + serach + "%")); } // and到一起的话所有条件就是且关系,or就是或关系 return cb.and(predicates.toArray(new Predicate[predicates.size()])); } }; resultList = this.adviceDao.findAll(querySpecifi); return resultList;