spring-data-jpa

between and

between and 获取的是闭区间的数据,如:[100,200]

复杂查询分页

 * 查询某个栏目下的所有文章,并且分页。 *  * 如该栏目下有子栏目,则需要一起显示 *  * @param channelId 栏目id * @param searchParams * @param pageNumber * @param pageSize * @return */ public Page getContentListPaged(final Integer channelId,final Collection filters,int pageNumber, int pageSize){ return contentDao.findAll(new Specification(){ @Override public Predicate toPredicate(Root root,                  CriteriaQuery query, CriteriaBuilder builder) { //path转化 List orPredicates = Lists.newArrayList();                                Path idPath = root.get("channel").get("id");                Path parentIdsPath = root.get("channel").get("parentIds");                              Predicate p1 = builder.equal(root.get("channel").get("id"), channelId);             orPredicates.add(builder.or(p1));               Predicate p2 = builder.like((Path)root.get("channel").get("parentIds"), "%," + channelId + ",%");               orPredicates.add(builder.or(p2)); //以下是springside3提供的方法 Predicate o = DynamicSpecifications.bySearchFilter(filters, Content.class).toPredicate(root, query, builder);                            Predicate p = builder.or(orPredicates.toArray(new Predicate[orPredicates.size()]));             query.where(p,o); return null;                         }                   }, new PageRequest(pageNumber - 1, pageSize));  }

你可能感兴趣的:(spring-data-jpa)