public Page<ReportTask> getListByPage(ReportTaskQueryDto reportTaskQueryDto) { final Integer offset = reportTaskQueryDto.getOffset(); final Integer limit = reportTaskQueryDto.getLimit(); Sort sort = Sort.sort(ReportTask.class).by(ReportTask::getCreateTime).descending(); PageRequest pageRequest = PageRequest.of(offset, limit, sort); Specification<ReportTask> specification = (root, query, criteriaBuilder) -> { Predicate predicate = criteriaBuilder.conjunction(); List<Expression<Boolean>> expressions = predicate.getExpressions(); if (!Objects.isNull(reportTaskQueryDto.getTaskName())) { expressions.add(criteriaBuilder.like(root.get("taskName"), "%" + reportTaskQueryDto.getTaskName() + "%")); } if (!Objects.isNull(reportTaskQueryDto.getStatus())) { expressions.add(criteriaBuilder.equal(root.get("status"), reportTaskQueryDto.getStatus())); } return predicate; }; return reportTaskRepository.findAll(specification, pageRequest); }
标签:reportTaskQueryDto,sort,predicate,分页,JPA,查询,criteriaBuilder,expressions,root From: https://www.cnblogs.com/shangwei/p/17083887.html