between and
between and 获取的是闭区间的数据,如:[100,200]
复杂查询分页
* 查询某个栏目下的所有文章,并且分页。 * * 如该栏目下有子栏目,则需要一起显示 * * @param channelId 栏目id * @param searchParams * @param pageNumber * @param pageSize * @return */ public Page<Content> getContentListPaged(final Integer channelId,final Collection<SearchFilter> filters,int pageNumber, int pageSize){ return contentDao.findAll(new Specification<Content>(){ @Override public Predicate toPredicate(Root<Content> root, CriteriaQuery<?> query, CriteriaBuilder builder) { //path转化 List<Predicate> orPredicates = Lists.newArrayList(); Path<String> idPath = root.get("channel").get("id"); Path<String> 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)); }
网友评论