java springboot +jpa 动态查询分页问题

service 层

 PageRequest pageRequest = new PageRequest(currentPage-0,pageSize);

        List<AuditInfo> auditInfoList =  auditInfoDAO.searchByCondition(date1,date2,new Specification<AuditInfo>() {
                @Override
                public Predicate toPredicate(Root<AuditInfo> root, CriteriaQuery<?> query, CriteriaBuilder cb) {
                    List<Predicate> list = new ArrayList<>();

                    if(!StringUtils.isEmpty(username)){
                        list.add(cb.equal(root.get("userName").as(String.class),username));
                    }

                    if(!StringUtils.isEmpty(condition)){
                        list.add(cb.equal(root.get("parentType").as(String.class),condition));
                    }
                    query.where(cb.and(list.toArray(new Predicate[list.size()])));
                    return query.getRestriction();
                }
        },pageRequest);

dao:

 @Query(value="select audit from AuditInfo audit where audit.createTime>=?1 and audit.createTime<= ?2 ")
    List<AuditInfo> searchByCondition(Date start,Date end,Specification<AuditInfo> specification,Pageable pageable);

查询得到的一直是全部的结果,筛选条件 无效

Csdn user default icon
上传中...
上传图片
插入图片
抄袭、复制答案,以达到刷声望分或其他目的的行为,在CSDN问答是严格禁止的,一经发现立刻封号。是时候展现真正的技术了!
立即提问