这里简单示例,利用query,根据“createtime”字段,进行 desc 排序,最近日期的数据在最前面。

public List<StatusEvent> findAll(Specification<User> spec);

    map.addAttribute("resultList",statusEventRes.findAll(new Specification<User>(){

    @Override
public Predicate toPredicate(Root<User> root, CriteriaQuery<?> query,
CriteriaBuilder cb) { List<Predicate> list = new ArrayList<Predicate>(); Predicate p1 = cb.or(cb.equal(root.get("discalled").as(String.class), ani2),cb.equal(root.get("discaller").as(String.class), ani2)); list.add(p1); Predicate[] p = new Predicate[list.size()]; query.where(cb.and(list.toArray(p))); query.orderBy(cb.desc(root.get("createtime"))); return query.getRestriction(); }}));

  

05-21 04:02