Spring JPA in查询

in的用法和equal,like,or的用法不同!
List> querySpecs = new ArrayList<>();
querySpecs.add(
      (Root root, CriteriaQuery query, CriteriaBuilder criteriaBuilder) ->
          criteriaBuilder.equal(root.get(TaskExecutionLog_.executor), executor));

querySpecs.add(
      (Root root, CriteriaQuery query, CriteriaBuilder criteriaBuilder) ->
          criteriaBuilder.like(root.get(TaskExecutionLog_.meta), "%"+snId+"%"));

querySpecs.add(
      (Specification) (root, query, criteriaBuilder) ->                      
           criteriaBuilder.or(criteriaBuilder.equal(root.get("status"),
            split[0]),criteriaBuilder.equal(root.get("status"), split[1])));

List storeSerialNoList = feignBrandClient.getStoreByHeadStoreName(headStoreName);
if (storeSerialNoList != null && storeSerialNoList.size() > 0) {
    querySpecs.add(
            (Root root, CriteriaQuery query, CriteriaBuilder criteriaBuilder) -> {
              List list = new ArrayList<>();
              if (storeSerialNoList != null && storeSerialNoList.size() > 0) {
                CriteriaBuilder.In in = criteriaBuilder.in(root.get(TaskExecutionLog_.storeSerialNo));
                for (String storeSerialNo : storeSerialNoList) {
                  in.value(storeSerialNo);
                }
                list.add(in);
              }
              Predicate[] p = new Predicate[list.size()];
              return criteriaBuilder.and(list.toArray(p));
            });
} 
  
Sort sort = Sort.by(Sort.Direction.DESC, "lastModifiedTime");
if (!StringUtils.isEmpty(sorter)) {
  sort = PageUtils.parseSort(sorter);
}
return taskService.queryAllLogs(querySpecs, PageUtils.loadPage(offset, limit, sort));

你可能感兴趣的:(JPA)