JpaSpecificationExecutor
public interface CustomerRepository extends CrudRepository<Customer, Long>, JpaSpecificationExecutor {
…
}
public interface JpaSpecificationExecutor<T> {
T findOne(Specification<T> var1);
List<T> findAll(Specification<T> var1);
Page<T> findAll(Specification<T> var1, Pageable var2);
List<T> findAll(Specification<T> var1, Sort var2);
long count(Specification<T> var1);
}
List<T> findAll(Specification<T> var1);
org.springframework.data.jpa.domain.Specification
Specification specification = new Specification() {
@Override
public Predicate toPredicate(Root root, CriteriaQuery criteriaQuery, CriteriaBuilder criteriaBuilder) {
return null;
}
}
/**
* A root type in the from clause.
* Query roots always reference entities.
*
* @param <X> the entity type referenced by the root
* @since Java Persistence 2.0
*/
public interface Root<X> extends From<X, X> {...}
/**
* Used to construct criteria queries, compound selections,
* expressions, predicates, orderings.
*
* <p> Note that <code>Predicate</code> is used instead of <code>Expression<Boolean></code>
* in this API in order to work around the fact that Java
* generics are not compatible with varags.
*
* @since Java Persistence 2.0
*/
public interface CriteriaBuilder {...}
criteriaBuilder.lessThan(root.get("createDate"), today)
/** * Create a conjunction of the given restriction predicates. * A conjunction of zero predicates is true. * * @param restrictions zero or more restriction predicates * * @return and predicate */ Predicate and(Predicate... restrictions);
/** * Create a disjunction of the given restriction predicates. * A disjunction of zero predicates is false. * * @param restrictions zero or more restriction predicates * * @return or predicate */ Predicate or(Predicate... restrictions);
public List<WeChatGzUserInfoEntity> findByCondition(Date minDate, Date maxDate, String nickname){
List<WeChatGzUserInfoEntity> resultList = null;
Specification querySpecifi = new Specification<WeChatGzUserInfoEntity>() {
@Override
public Predicate toPredicate(Root<WeChatGzUserInfoEntity> root, CriteriaQuery<?> criteriaQuery, CriteriaBuilder criteriaBuilder) {
List<Predicate> predicates = new ArrayList<>();
if(null != minDate){
predicates.add(criteriaBuilder.greaterThan(root.get("subscribeTime"), minDate));
}
if(null != maxDate){
predicates.add(criteriaBuilder.lessThan(root.get("subscribeTime"), maxDate));
}
if(null != nickname){
predicates.add(criteriaBuilder.like(root.get("nickname"), "%"+nickname+"%"));
}
return criteriaBuilder.and(predicates.toArray(new Predicate[predicates.size()]));
}
};
resultList = this.weChatGzUserInfoRepository.findAll(querySpecifi);
return resultList;
}
机械节能产品生产企业官网模板...
大气智能家居家具装修装饰类企业通用网站模板...
礼品公司网站模板
宽屏简约大气婚纱摄影影楼模板...
蓝白WAP手机综合医院类整站源码(独立后台)...苏ICP备2024110244号-2 苏公网安备32050702011978号 增值电信业务经营许可证编号:苏B2-20251499 | Copyright 2018 - 2025 源码网商城 (www.ymwmall.com) 版权所有