1.继承接口
2.下面是简单的操作---自己写过的,下次再整理一下
public Pagelist(MemberSearch search, Pageable pageable) { Page page = memberRepository.findAll((root, query, cb) -> { List predicates = new ArrayList<>(); //groupId if (StringUtils.isNotEmpty(search.getSearchGroupId())) { predicates.add((cb.equal(root.get("idddsMemberGroup").get("id"), search.getSearchGroupId()))); } else { CriteriaBuilder.In in = cb.in(root.get("idddsMemberGroup").get("id")); List groupIdList = memberGroupRepository.findIdsByStatus(StatusEnum.normal.getDesc()); for (String str : groupIdList) { in.value(str); } predicates.add(in); } //role角色 if (StringUtils.isNoneBlank(search.getSearchRole())) { predicates.add((cb.equal(root.get("role"), search.getSearchRole()))); } //status状态 if (StringUtils.isNoneBlank(search.getSearchStatus())) { predicates.add((cb.equal(root.get("status"), search.getSearchStatus()))); } //名字,公司模糊查询 if (StringUtils.isNoneBlank(search.getSearchName())) { predicates.add((cb.like(root.get("trueName"), "%" + search.getSearchName() + "%"))); } if (StringUtils.isNoneBlank(search.getSearchOrganization())) { predicates.add((cb.like(root.get("organization"), "%" + search.getSearchOrganization() + "%"))); } //时间,这里是个坑,数据库字段为created_time if (search.getStart() != null) { predicates.add(cb.greaterThanOrEqualTo(root.get("createdTime"), DateUtils .parseDate(DateUtils.formatDate(search.getStart(), "yyyy-MM-dd") + " 00:00:00"))); } if (search.getEnd() != null) { predicates.add(cb.lessThanOrEqualTo(root.get("createdTime"), DateUtils .parseDate(DateUtils.formatDate(search.getEnd(), "yyyy-MM-dd") + " 23:59:59"))); } query.where(predicates.toArray(new Predicate[]{})); //排序 if (StringUtils.isNoneBlank(search.getOrderBy())) { if ("desc".equals(search.getSortType())) { //倒序 query.orderBy(cb.desc(root.get(search.getOrderBy()))); } else { //正序 query.orderBy(cb.asc(root.get(search.getOrderBy()))); } } return null; }, pageable); return page; }