public Page findByPage(Integer page, Integer pageCount,Integer type) {
if(page==null||pageCount==null){
page=1;
pageCount=20;
}
Pageable pageable = PageRequest.of(page - 1, pageCount);
Page<IosApp> pageList = iosAppDao.findAll((Specification<IosApp>) (root, query, cb) -> {
List<Predicate> list = new ArrayList<>();
if(type!=null){
Join<IosApp, IosAppCategory> join = root.join("category", JoinType.LEFT);
list.add(cb.equal(join.get("type"),type));
}
Join<IosApp, IosAppCategory> join = root.join("favUserList", JoinType.LEFT);
Predicate[] predicates = list.toArray(new Predicate[list.size()]);
List<Order> orderList = new ArrayList<>();
orderList.add(cb.desc(cb.count(join))) ;
query.where(cb.and(list.toArray(predicates)));
query.groupBy(root.get("appId"));
query.orderBy(orderList);//排序
return cb.and(predicates);
},pageable);
return pageList;
}
jpa多对多根据关联的数量进行排序
最新推荐文章于 2023-07-11 10:00:00 发布