Hibernate进行模糊查询
来源:互联网 发布:数据备份 方案 编辑:程序博客网 时间:2024/05/29 12:24
一、绑定参数法:
- 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进行模糊查询
- Hibernate在Oracle数据库中进行模糊查询日期
- Hibernate中如何用HQL进行模糊查询
- hibernate的Restrictions对数字型即整型进行模糊查询
- hibernate用like进行模糊查询时不能写单引号!!!
- hibernate query 模糊查询
- Hibernate-Criteria 模糊查询
- Hibernate模糊查询参数
- Hibernate-Criteria 模糊查询
- [Hibernate]hibernateTemplate模糊查询
- Hibernate模糊查询
- Hibernate-Criteria 模糊查询
- hibernate 模糊查询
- Hibernate模糊查询
- [JAVA]Hibernate模糊查询
- hibernate HQL 模糊查询
- Hibernate中文模糊查询
- Hibernate模糊查询
- Android引导页设计
- javaScript 定时器
- Flexbox布局技术研究
- 页面中插入QQ表情
- C#的Infinity和NaN
- Hibernate进行模糊查询
- Cordova 环境搭建(Window)
- JavaScript上传图片前预览
- c语言格式字符串 % lf 和 %f
- 练习2————1014
- 如何处理Permission denied: user=root, access=WRITE, inode="/user" 这类Hadoop权限问题问题
- X264编码
- linux 下安装 nginx
- spring中事务的管理基于xml和注解,以及spring在web中应用