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));
    }
    });





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

  • 相关阅读:
    ssh链接服务器并且拷贝文件
    php读取文件内容
    appendchild的两个正确用法以及ajax
    创业点滴
    随笔——支持IE8的一个ajax的标准写法。
    添加评论,查看评论等——在线留言板4
    删除留言和更新留言——在线留言板3
    git常用命令
    浏览器版本控制
    洛谷 P2296 【寻找道路】
  • 原文地址:https://www.cnblogs.com/michaelcnblogs/p/13287838.html
Copyright © 2011-2022 走看看