springboot jpa 使用Predicate进行in条件查询


List<Long> list = new ArrayList<>();
list.add(1l);
list.add(2l);

@Override
public Predicate toPredicate(Root<xxx> root, CriteriaQuery<?> criteriaQuery, CriteriaBuilder criteriaBuilder) {
 	List<Predicate> predicateList= new ArrayList<>()
	if (list != null && list.size() > 0){
	      predicateList.add(root.<Long>get("xxx").in(list));
	 } 
	criteriaQuery.where(criteriaBuilder.and(predicateList.toArray(new Predicate[predicateList.size()])));    
	return criteriaQuery.getRestriction();
}

你可能感兴趣的:(程序员开发笔记,spring,boot,后端,java)