zoukankan      html  css  js  c++  java
  • JPA多条件查询

    Page<AoaQuestionHeader> findAll(Specification<AoaQuestionHeader> spec, Pageable pageable);
    List<AoaQuestionHeader> headerPage = questionHeaderDao.findAll(new Specification<AoaQuestionHeader>(){
        @Override
    public Predicate toPredicate(Root<AoaQuestionHeader> root, CriteriaQuery<?> query, CriteriaBuilder cb) {
    List<Predicate> list = new ArrayList<Predicate>();
    if (!typeId.equals(0L)){
    list.add(cb.equal(root.get("typeId").as(Long.class),typeId)) ;
    }
    if (!groupId.equals(0L)){
    list.add(cb.equal(root.get("groupId").as(Long.class), groupId)) ;
    }
    if (!leaderId.equals(0L)){
    list.add(cb.equal(root.get("leaderId").as(Long.class), leaderId) );
    }
    Predicate[] p = new Predicate[list.size()];
    return cb.and(list.toArray(p));
    }
    }, new PageRequest(page,size , sort));




    List<AoaQuestionHeader> findAll(Specification<AoaQuestionHeader> spec);

    List<AoaQuestionHeader> hlist = questionHeaderDao.findAll(new Specification<AoaQuestionHeader>(){
        @Override
    public Predicate toPredicate(Root<AoaQuestionHeader> root, CriteriaQuery<?> query, CriteriaBuilder cb) {
    List<Predicate> list = new ArrayList<Predicate>();
    if (!typeId.equals(0L)){
    list.add(cb.equal(root.get("typeId").as(Long.class),typeId)) ;
    }
    if (!groupId.equals(0L)){
    list.add(cb.equal(root.get("groupId").as(Long.class), groupId)) ;
    }
    if (!leaderId.equals(0L)){
    list.add(cb.equal(root.get("leaderId").as(Long.class), leaderId) );
    }
    Predicate[] p = new Predicate[list.size()];
    return cb.and(list.toArray(p));
    }
    });





    这么个意思,自己的笔记看不懂勿用

  • 相关阅读:
    linux 命令
    linux 后门防范
    linux date
    shell 常用参数
    linux rule策略
    vlan对服务器要注意的事情
    STL vector——c++
    蛇形矩阵
    简单a+b
    小 X 与数字(ten)
  • 原文地址:https://www.cnblogs.com/michaelcnblogs/p/13287838.html
Copyright © 2011-2022 走看看