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);
查询得到的一直是全部的结果,筛选条件 无效