jpa Specification複雑なクエリー
2864 ワード
public List test(List costIds){
Specification specification1= (Root root, CriteriaQuery> query, CriteriaBuilder cb)-> {
Predicate restrictions = cb.conjunction();
// List restrictions = new ArrayList();
if (null != costIds) {
Join join = root.join("addReceiptsCostVOList",JoinType.LEFT);
// Fetch fetch=root.fetch("addReceiptsCostVOList",JoinType.LEFT);
// restrictions = cb.and(restrictions,root.get("addReceiptsCostVOList").get("costId").in(costIds));
// get("costchanges").get("costchangeApplyId")
// root.fetch("addReceiptsCostVOList");
restrictions=cb.and(join.get("costId").in(costIds));
}
// Predicate[] p = new Predicate[restrictions.size()];
// return cb.and(restrictions.toArray(p));
query.where(restrictions);
query.distinct(true);
return query.getRestriction();
};
// List receiptsList=receiptsRepository.findAll(specification1);
return null;
}
CriteriaQuery ,
参照先:https://blog.csdn.net/baijunzhijiang_01/article/details/51557125