- JPA Repository 继承JpaSpecificationExecutor
public interface VwUserEstateRepository extends CrudRepository<VwUserEstate, Integer> , JpaSpecificationExecutor<VwUserEstate> {
protected static Specification<VwUserEstate> queryNotSendByTerms(Integer projectId, Integer materialCodeId, Integer batchId, Integer estateTypeId, Integer estateSubTypeId, List<Integer> estateIds, Integer uid) {
return new Specification<VwUserEstate>() {
public Predicate toPredicate(Root<VwUserEstate> root, CriteriaQuery<?> query, CriteriaBuilder builder) {
Predicate predicate = builder.conjunction()
if (projectId != null) {
predicate.getExpressions().add(builder.equal(root.get(VwUserEstate_.projectId), projectId))
}
if (materialCodeId != null) {
predicate.getExpressions().add(builder.equal(root.get(VwUserEstate_.materialCodeId), materialCodeId))
}
if (batchId != null) {
predicate.getExpressions().add(builder.equal(root.get(VwUserEstate_.batchId), batchId))
}
if (estateTypeId != null) {
predicate.getExpressions().add(builder.equal(root.get(VwUserEstate_.estateTypeId), estateTypeId))
}
if (estateSubTypeId != null) {
predicate.getExpressions().add(builder.equal(root.get(VwUserEstate_.estateSubTypeId), estateSubTypeId))
}
Iterator iterator = estateIds.iterator()
In in = builder.in(root.get(VwUserEstate_.id))
while (iterator.hasNext()) {
in.value(iterator.next())
}
predicate.getExpressions().add(builder.not(in))
predicate.getExpressions().add(builder.equal(root.get(VwUserEstate_.uid), uid))
return predicate
}
}
}
Page<VwUserEstate> list = vwUserEstateRepository.findAll(where(queryNotSendByTerms(projectId, materialCodeId, batchId, estateTypeId, estateSubTypeId, estateIds, uid)), page);