zoukankan      html  css  js  c++  java
  • Spring Data Jpa-动态查询条件

        /**
         * 
         * 查看日志列表-按照时间倒序排列
         * 
         * @author: wyc
         * @createTime: 2017年4月20日 下午4:24:43
         * @history:
         * @return List<SecurityAuditLog>
         */
        public Page<SecurityAuditLog> pageLogList(final SecurityAuditLog log,int page,int size){
            Sort s=new Sort(Sort.Direction.DESC, "operateTime");
            PageRequest p=new PageRequest(page-1, size, s);
            
             Specification querySpecifi = new Specification<SecurityAuditLog>() {
                    @Override
                    public Predicate toPredicate(Root<SecurityAuditLog> root, CriteriaQuery<?> criteriaQuery, CriteriaBuilder criteriaBuilder) {
    
                        List<Predicate> predicates = new ArrayList<>();
                        if(null != log.getLoginAccount()&&!"".equals(log.getLoginAccount())){
                            predicates.add(criteriaBuilder.like(root.<String>get("loginAccount"), "%"+log.getLoginAccount()+"%"));
                        }
                        
                        if(null != log.getQuerySign()&&!"".equals(log.getQuerySign())){
                            predicates.add(criteriaBuilder.like(root.<String>get("querySign"), "%"+log.getQuerySign()+"%"));
                        }
                        
                        if(null != log.getQueryType()&&!"".equals(log.getQueryType())){
                            predicates.add(criteriaBuilder.equal(root.<String>get("queryType"), log.getQueryType()));
                        }
                        
                        if(null != log.getOperatePlatform()&&!"".equals(log.getOperatePlatform())){
                            predicates.add(criteriaBuilder.equal(root.<String>get("operatePlatform"), log.getOperatePlatform()));
                        }
                        
                        if(null != log.getOperateModule()&&!"".equals(log.getOperateModule())){
                            predicates.add(criteriaBuilder.equal(root.<String>get("operateModule"), log.getOperateModule()));
                        }
                        
                        
                        return criteriaBuilder.and(predicates.toArray(new Predicate[predicates.size()]));
                    }
                };
            Page<SecurityAuditLog> list= securityAuditLogDao.findAll(querySpecifi,p);
            return list;
        }
    import org.springframework.data.jpa.repository.JpaSpecificationExecutor;
    import org.springframework.data.repository.PagingAndSortingRepository;public interface ISecurityAuditLogDao extends PagingAndSortingRepository<SecurityAuditLog, String>,JpaSpecificationExecutor<SecurityAuditLog>{
    
    }
  • 相关阅读:
    Baum Welch估计HMM参数实例
    SVM 为什么要从原始问题变为对偶问题来求解
    Baum-Welch算法(EM算法)对HMM模型的训练
    LR采用的Sigmoid函数与最大熵(ME) 的关系
    01背包的常数优化的一点解释
    训练中文词向量
    TensorFlow L2正则化
    TensorFlow batch normalize的使用
    听说你的模型损失是NaN
    编译TensorFlow CPU指令集优化版
  • 原文地址:https://www.cnblogs.com/wuyechun/p/7171312.html
Copyright © 2011-2022 走看看