当前位置: 首页 > 工具软件 > ListPage > 使用案例 >

SpringBoot JPA(JpaRepository)动态查询 返回list ,返回page

沙海
2023-12-01
    @Override
    public List<BillSalesBase> findAllByCondition(String type){
        List<BillSalesBase> resultList = null;
        Specification querySpecifi = new Specification<BillSalesBase>() {
            public Predicate toPredicate(Root<BillSalesBase> root, CriteriaQuery<?> criteriaQuery, CriteriaBuilder criteriaBuilder) {
                List<Predicate> predicates = new ArrayList<>();
                if(null != type){
                    predicates.add(criteriaBuilder.like(root.get("bill_type"), "%"+type+"%"));
                }

                return criteriaBuilder.and(predicates.toArray(new Predicate[predicates.size()]));
            }
        };
        resultList =  billSalesBaseJpa.findAll(querySpecifi);
        return resultList;
    }
 @Override
    public Page<PrpsCommisionTaxInfo> findAllByConditions(String businessno,String usercode,String yearmonth,Pageable pageable){
        Page<PrpsCommisionTaxInfo> resultList = null;
        Specification querySpecifi = new Specification<PrpsCommisionTaxInfo>() {
            public Predicate toPredicate(Root<PrpsCommisionTaxInfo> root, CriteriaQuery<?> criteriaQuery, CriteriaBuilder criteriaBuilder) {
                List<Predicate> predicates = new ArrayList<>();
                if(null != businessno){
                    predicates.add(criteriaBuilder.like(root.get("businessno"), "%"+businessno+"%"));
                }
                if(null != usercode){
                    predicates.add(criteriaBuilder.like(root.get("usercode"), "%"+usercode+"%"));
                }
                if(null != yearmonth){
                    predicates.add(criteriaBuilder.like(root.get("yearmonth"), "%"+yearmonth+"%"));
                }
                return criteriaBuilder.and(predicates.toArray(new Predicate[predicates.size()]));
            }
        };
        resultList =  prpsCommisionTaxInfoJpa.findAll(querySpecifi,pageable);
        return resultList;
    }

 

 类似资料: