mrywTopPage = articleRepository.findAll((root, query, cb) -> {
List<Predicate> predicateList = new ArrayList<>();
if (!itemId.equals("all")) {
Join<Article, ArticleLabel> articleLabelJoin = root.join("articleLabels", JoinType.INNER);
articleLabelJoin.on(cb.equal(articleLabelJoin.get("id").get("labelId"), itemId));
}
if (labelList.size() > 0) {
Join<Article, ArticleLabel> labelJoin = root.join("articleLabels", JoinType.INNER);
labelJoin.on(labelJoin.get("id").get("labelId").in(labelList));
}
predicateList.add(cb.equal(root.get("type"), 1));
predicateList.add(cb.equal(root.get("status"), "已发布"));
predicateList.add(cb.notEqual(root.get("sortNum"), 2147483647));
query.where(predicateList.toArray(new Predicate[]{
}));
query.orderBy(cb.desc(root.get("updateTime")));
return null;
}, pageable);
public Page<Employee> findSubquery(Pageable pageable) {
Page<Employee> page = employeeRepository.findAll((root, criteriaQuery, criteriaBuilder) -> {
List<Predicate> predicateList = new ArrayList<>();
Subquery<Integer> deptSubquery = criteriaQuery.subquery(Integer.class);
Root<Dept> deptRoot = deptSubquery.from(Dept.class);
List<Predicate> deptPredicateList = new ArrayList<>();
deptPredicateList.add(criteriaBuilder.equal(deptRoot.get("location"), "NEW YORK"));
deptPredicateList.add(criteriaBuilder.like(deptRoot.get("dname"),"%ACC%"));
deptSubquery.select(deptRoot.get("deptno")).where(deptPredicateList.toArray(new Predicate[]{
}));
predicateList.add(root.get("dept").get("deptno").in(deptSubquery));
criteriaQuery.where(predicateList.toArray(new Predicate[]{
}));
criteriaQuery.orderBy(criteriaBuilder.desc(root.get("empno")));
return null;
}, pageable);
return page;
}