随便记录

private Specification<CuserQuestion> buildSpecification(CuserQuestionDTO cuserQuestionDTO) {
return new Specification<CuserQuestion>() {
public Predicate toPredicate(Root<CuserQuestion> root, CriteriaQuery<?> query, CriteriaBuilder builder) {
List<Predicate> predicate = new ArrayList<Predicate>();

if (!CheckParam.isNull(cuserQuestionDTO.getContent())) {
predicate.add(builder.like(root.get("content"), "%" + cuserQuestionDTO.getContent() + "%"));
}

if (!CheckParam.isNull(cuserQuestionDTO.getStatus())) {
predicate.add(builder.equal(root.get("status"),cuserQuestionDTO.getStatus()));
}

if (!CheckParam.isNull(cuserQuestionDTO.getEndTime())) {
predicate.add(builder.between(root.get("createTime"),cuserQuestionDTO.getStartTime(),cuserQuestionDTO.getEndTime()));
}
predicate.add(builder.equal(root.get("isDelete"),0));
Predicate[] pre = new Predicate[predicate.size()];
return query.where(predicate.toArray(pre)).getRestriction();
}
};
}

 

ParamConfig paramConfig = new ParamConfig();
Integer pageSize = paramConfig.getPageSize(commentOrderDTO.getPageSize());
Integer pageOne = paramConfig.getPageNo(commentOrderDTO.getPageOne());

Sort sort = new Sort(Sort.Direction.DESC, "id");
Pageable pageable = PageRequest.of(pageOne,pageSize ,sort);

posted @ 2018-12-07 16:04  全栈冲鸭!  阅读(158)  评论(0编辑  收藏  举报