美文网首页
hibernate in语句使用和占位符

hibernate in语句使用和占位符

作者: 刷爆服务器 | 来源:发表于2018-07-22 00:42 被阅读0次
    public List<Book> searchBookByISBNList(List<String> ISBN){
        session = sessionFactory.openSession();
        tx = session.beginTransaction();
        String sql ="select b from Book b where b.ISBN in (:ISBNList)"; //命名参数查询
        Query query=session.createQuery(sql);
        query.setParameterList("ISBNList", ISBN);
        List <Book> list=query.list();
        tx.commit();
        session.close();
        if(list.size() == 0) return null;
        else return list;
    }
    public List<Book> searchBookByISBNList(List<String> ISBN){
        session = sessionFactory.openSession();
        tx = session.beginTransaction();
        String sql ="select b from Book b where b.ISBN in (?0)"; //JPA占位符查询
        Query query=session.createQuery(sql);
        query.setParameterList("0", ISBN);
        List <Book> list=query.list();
        tx.commit();
        session.close();
        if(list.size() == 0) return null;
        else return list;
    }
    public List<Book> searchBookByISBNList(List<String> ISBN){
        session = sessionFactory.openSession();
        tx = session.beginTransaction();
        String sql ="select b from Book b where b.ISBN in (?)"; //老的占位符查询
        Query query=session.createQuery(sql);
        query.setParameterList("0", ISBN);
        List <Book> list=query.list();
        tx.commit();
        session.close();
        if(list.size() == 0) return null;
        else return list;
    }

相关文章

  • hibernate in语句使用和占位符

  • 在Hibernate5中HQL查询使用"?"

    参考博文: 关于在Hibernate5.3.1中HQL语句使用"?"参数占位符运行报错的问题

  • SQLite3 执行 sql 语句的占位符

    使用 execute 方法执行一条SQL语句,如果带有参数可以使用占位符来传递参数。使用占位符已经考虑到转码的问...

  • Glide4 使用

    基本使用Glide.with(this).load(url).into(imageView); 使用占位符占位符是...

  • 莹莹

    占位符占位符占位符占位符占位符占位符占位符占位符占位符占位符占位符占位符占位符占位符占位符占位符占位符占位符占位符...

  • 莹莹

    占位符占位符占位符占位符占位符占位符占位符占位符占位符占位符占位符占位符占位符占位符占位符占位符占位符占位符占位符...

  • 操作FMDB执行sql语句遇到carsh现象

    在操作FMDB插入的时候,如果遇到了carsh,需要检查sql语句中是否使用了?占位符 (不确定的参数用?来占位)...

  • 随笔

    1.占位符% %s表示占位符类型是str字符串类型%d表示占位符类型是digital数字类型使用占位符的时候,还需...

  • #{}和${}应用场景

    #{}sql语句中;//占位符== ?spel注入方式中; //#{user1.name} ${}sql语句中;...

  • 随记

    MySQL与 PostgreSQL 预处理(Prepared) 匿名占位符 MySQL: 使用 ? 作为匿名占位符...

网友评论

      本文标题:hibernate in语句使用和占位符

      本文链接:https://www.haomeiwen.com/subject/wmokmftx.html