转载:
http://blog.csdn.net/anxpp/article/details/51996472
https://www.cnblogs.com/derry9005/p/6282571.html
列如
Specification<DebtsEntity> specification = new Specification<DebtsEntity>() { public Predicate toPredicate(Root<DebtsEntity> root, CriteriaQuery<?> query, CriteriaBuilder cb) { Predicate prd = null; Predicate p0 = cb.notEqual(root.get("key1").as(String.class),"1"); Predicate p1 = cb.notEqual(root.get("key2").as(String.class),"2"); Predicate p2 = cb.equal(root.get("key3").as(String.class), "3"); Predicate p3 = cb.like(root.get("key4").as(String.class),"%"+name+"%"); prd=cb.and(p0,p1,p2,p3); query.where(prd); // 添加排序的功能 query.orderBy(cb.desc(root.get("key5"))); return query.getRestriction(); } }; Page<DebtsEntity> contactsPage = deptsDao.findAll(specification, pageable);