springboot-动态查询、分页和排序

 /**
     * 获取企业集合
     *
     * @return
     */
    public List getQy(String qymc, Integer page, Integer size) {
        List list = new ArrayList<>();

        Specification specification = new Specification() {

            @Override
            public Predicate toPredicate(Root root, CriteriaQuery criteriaQuery, CriteriaBuilder criteriaBuilder) {
                List predicates = new ArrayList<>();
                if (StringUtils.isNotBlank(qymc)) {
                    predicates.add(criteriaBuilder.like(root.get("qymc"), "%" + qymc + "%"));
                }
                return criteriaBuilder.and(predicates.toArray(new Predicate[predicates.size()]));
            }
        };
        Sort sort = new Sort(Sort.Direction.ASC, "qymc");
        Pageable pageable = new PageRequest((page - 1) / size, size, sort);
        Page qyPage = this.qyRepositpry.findAll(specification, pageable);
        List qyList = qyPage.getContent();
        return qyList;
    }

你可能感兴趣的:(spring)