hibernate 4.0模糊查询
来源:互联网 发布:c语言 char数组 编辑:程序博客网 时间:2024/05/16 05:01
大家都知道使用本地SQL进行模糊查询用关键字 LIKE 对于在hibernate里怎么实现呢?
一、绑定参数法:
- Session session=HibernateUtil.getSessionFactory
- ().getCurrentSession();
- session.beginTransaction();
- String strSQL="from Classes as a where a.classno like :name";
- Query query = session.createQuery(strSQL);
- query.setString("name", "%"+OId+"%");
- List result=query.list();
二、在面向对象的查询语言 HQL 中
- Session session = HibernateUtil.getSessionFactory().getCurrentSession();
- session.beginTransaction();
- List result=session.createQuery("from Classes as a where a.classno
- like " '%"+OId+"%'").list();
三、模糊查询参数化
- Session session=HibernateUtil.getSessionFactory().getCurrentSession();
- session.beginTransaction();
- List result=session.createQuery("from Classes as a where a.classno
- like :name").setParameter("pid",OId).list();
Hibernate模糊查询参数化的问题
from Project o where 1=1 and o.isDeleted=? and o.prjName like ?; query.setString(i, "%"+实际查询条件+"%"); 注意参数中第一个百分号的左边与第二个百分号的右边都没有单引号,这和平时写SQL语句是不同的,要特别关注一下。另外还应该了解一下俩点的区别
HQL:from Project o where 1=1 and PRJ_NAME like '%strCond%';//这里PRJ_NAME 应该是数据库表中的实际字段名
HQL:from Project o where 1=1 and o.PRJ_NAME like '%strCond%';//这里PRJ_NAME 应该是实体类的属性名
HQL:from Project o where 1=1 and PRJ_NAME like '?';//这里的?不视为占位参数HQL:from Project o where 1=1 and PRJ_NAME like ?;//设置参数值时会自动在参数值两边加上单引号。
0 0
- hibernate 4.0模糊查询
- hibernate query 模糊查询
- Hibernate-Criteria 模糊查询
- Hibernate模糊查询参数
- Hibernate-Criteria 模糊查询
- [Hibernate]hibernateTemplate模糊查询
- Hibernate模糊查询
- Hibernate-Criteria 模糊查询
- hibernate 模糊查询
- Hibernate模糊查询
- [JAVA]Hibernate模糊查询
- hibernate HQL 模糊查询
- Hibernate中文模糊查询
- Hibernate模糊查询
- Hibernate进行模糊查询
- Hibernate模糊查询
- Hibernate HQL查询 分页查询 模糊查询
- hibernate查询(模糊查询、子查询等)
- Palantir如何通过技术协助客户作业的,也是我看到过的讲大数据故事最精彩的一篇。
- 浅析java class文件格式
- 链表中环的入口结点
- CorelDRAW中如何实现抠图
- 【ANDROID】ASYNCTASK不回调ONPOSTEXECUTE方法的解决办法。
- hibernate 4.0模糊查询
- 回首栈与队列
- 矩形覆盖问题
- 在Centos7上搭建Objective-C环境
- HDU 1266 (模拟)
- @PropertySource
- jmx
- EPC-6708 arm 开发板常用命令等
- GitLab修改root用户密码