- 浏览: 1472264 次
- 性别:
- 来自: 深圳
文章分类
- 全部博客 (798)
- struts2 (42)
- servlet (20)
- quartz (4)
- jquery & ajax (24)
- tomcat (5)
- javascript (15)
- struts1 (8)
- 搜索关键字及链接 (3)
- fckeditor (3)
- Apache (5)
- spring (22)
- linux (3)
- 企业应用 (8)
- 综合应用 (13)
- 服务器 (2)
- 数据库 (85)
- 性能调优 (21)
- 网络应用 (15)
- 缓存技术 (8)
- 设计模式 (39)
- 面试题 (7)
- 程序人生&前辈程序员 (29)
- java基础 (59)
- hibernate (75)
- log4j (4)
- http (11)
- 架构设计 (28)
- 网页设计 (12)
- java邮件 (4)
- 相关工具 (11)
- ognl (7)
- 工作笔记 (18)
- 知识面扩展 (12)
- oracle异常 (1)
- 正则表达式 (2)
- java异常 (5)
- 项目实践&管理 (1)
- 专业术语 (11)
- 网站参考 (1)
- 论坛话题 (2)
- web应用 (11)
- cxf&webservice (22)
- freemarker (3)
- 开源项目 (9)
- eos (1)
- ibatis (6)
- 自定义标签 (3)
- jsp (3)
- 内部非公开文档(注意:保存为草稿) (0)
- 国内外知名企业 (2)
- 网店 (3)
- 分页 (1)
- 消费者习惯 (2)
- 每日关注 (1)
- 商业信息 (18)
- 关注商业网站 (1)
- 生活常识 (3)
- 新闻 (2)
- xml&JSON (5)
- solaris (1)
- apache.common (3)
- BLOB/CLOB (1)
- lucene (2)
- JMS (14)
- 社会进程 (8)
- SSH扩展 (2)
- 消费心理 (1)
- 珠三角 (1)
- 设计文档 (1)
- XWork&webwork (1)
- 软件工程 (3)
- 数据库及链接 (1)
- RMI (2)
- 国内外知名企业&人物 (1)
最新评论
-
司c马:
简介易懂、
OutputStream和InputStream的区别 -
在世界的中心呼喚愛:
解决我的问题
Java获取客户端的真实IP地址 -
bo_hai:
都是些基本的概念呀!
SSO -
tian_4238:
哥们,你也是搞水利这块的吧。
巧用SQLQuery中的addScalar -
loveEVERYday:
java.util.Date、java.sql.Date、java.sql.Time、java.sql.Timestamp小结
Criteria criteria = session.createCriteria(TaDiagnoseSystem.class);
//增加查询条件
if(StringUtils.isNotEmpty(systemName)){
// criteria.createCriteria("taDiagnoseSystemSubs").add(Restrictions.ilike("systemName", systemName, MatchMode.ANYWHERE));
criteria.createCriteria("taDiagnoseSystemSubs").add(Expression.like("systemName", "%"+systemName+"%"));
}
今天的项目中在用Hibernate3.0进行模糊查询的时候,出现中文乱码,在网上查了好久资料,终于解决了,现在把整理后的贴出来。
Hibernate中实现模糊查询,可有以下三种方式:
第一种方式:QBC查询
String name = "", info = "";
if (sub != null && sub.getSubname() != null) {
name = sub.getSubname();
}
if (sub != null && sub.getSubinfo() != null) {
info = sub.getSubinfo();
}
Criteria cr = session.createCriteria(Subject.class);
cr.add(Expression.like("subname","%"+name+"%"));
cr.add(Expression.like("subinfo","%"+info+"%"));
第二种方式:HQL查询语句
String hql = "from Subject as s where s.subname like :name and s.subinfo like :info";
// 调用session的获得数据列表方法,传递HQL查询语句
String subnamevalue="要查询的中文值";
String sql="";
sql = "from Pfapp where name like :subname ";
Query query = session.createQuery(sql);
query.setString("subname","%"+subnamevalue+"%");
System.out.println("*********"+sql);
注:Subject为数据库表subject映射的类;它有相应的属性subname、subinfo及相应的get和set方法;sub为Subject的一个实例化对象。
另外说明的是:如果你不写对象名称,直接写字段,那么hibernate就按照数据库字段进行查找
如果你写 (对象名.对象属性),那么hibernate就按照ormapping中的映射字段进行查找
Hibernate中实现模糊查询,可有以下三种方式:
第一种方式:QBC查询
String name = "", info = "";
if (sub != null && sub.getSubname() != null) {
name = sub.getSubname();
}
if (sub != null && sub.getSubinfo() != null) {
info = sub.getSubinfo();
}
Criteria cr = session.createCriteria(Subject.class);
cr.add(Expression.like("subname","%"+name+"%"));
cr.add(Expression.like("subinfo","%"+info+"%"));
第二种方式:HQL查询语句
String hql = "from Subject as s where s.subname like :name and s.subinfo like :info";
// 调用session的获得数据列表方法,传递HQL查询语句
String subnamevalue="要查询的中文值";
String sql="";
sql = "from Pfapp where name like :subname ";
Query query = session.createQuery(sql);
query.setString("subname","%"+subnamevalue+"%");
System.out.println("*********"+sql);
注:Subject为数据库表subject映射的类;它有相应的属性subname、subinfo及相应的get和set方法;sub为Subject的一个实例化对象。
另外说明的是:如果你不写对象名称,直接写字段,那么hibernate就按照数据库字段进行查找
如果你写 (对象名.对象属性),那么hibernate就按照ormapping中的映射字段进行查找
发表评论
-
自定义用户类(UserType)的使用
2011-08-04 10:46 1792学习hibernate有段时间了,最近复习这门技术时看到了自定 ... -
技巧:利于ThreadLocal模式管理Session
2011-08-02 10:31 1224在利用Hibernate开发DAO模块时,我们和Session ... -
Hibernate中的回调与拦截机制
2011-07-27 17:31 1424在某些情况下,我们需要对实体的CURD操作进行捕获并执行一些操 ... -
HibernateTemplate中HibernateCallback的事务
2011-07-04 14:41 1400目的:使用HibernateTemplate执行execute ... -
Hibernate的复杂用法HibernateCallback
2011-07-04 14:40 1290HibernateTemplate还提供一种更加灵活的方式来操 ... -
Hibernate session FlushMode有五种属性
2011-07-04 13:59 16861、NEVER:已经废弃了,被MANUAL取代了2 MANUA ... -
数据库持久层——浅谈hibernate中的Session
2011-07-01 22:49 1629大多数情况下,Session 管理的目标聚焦于通过合理的设 ... -
详解Hibernate Session
2011-07-01 22:42 1448这里介绍Hibernate Session,Ses ... -
HttpSession与Hibernate中Session的区别
2011-07-01 22:41 1238一、javax.servlet.http.HttpSess ... -
巧用SQLQuery中的addScalar
2011-06-02 17:16 5697当我们用HQL进行子查询的时候,如select * from ... -
hibernate中SQLQuery的addEntity();方法
2011-04-13 14:48 2855如果使用原生sql语句进行query查询时,hibernate ... -
Hibernate的clear(),flush(),evict()方法详解
2011-03-24 11:18 17311.Clear 方法 无论是Load 还是 G ... -
Hibernate分页查询小结
2011-03-10 11:14 1793通常使用的Hibernate通常是三种:hql查询,QBC查询 ... -
current_session_context_class
2011-03-07 15:31 1254此设置的作用如下: What does sessionFac ... -
Hibernate的拦截器和监听器
2010-12-14 15:06 1352核心提示:最近项目需要,用到了Hibernate的拦截器和 ... -
孙卫琴.精通Hibernate:Java对象持久化技术详解_触发器使缓存与数据库不一致
2010-12-14 08:46 1338p198 -
孙卫琴.精通Hibernate:Java对象持久化技术详解_优化报表查询的性能
2010-12-13 17:51 1238p332 -
孙卫琴.精通Hibernate:Java对象持久化技术详解_查询结果类型
2010-12-13 17:34 1268p329 -
孙卫琴.精通Hibernate:Java对象持久化技术详解_投影查询
2010-12-13 17:31 1376p325 -
深入浅出hibernate_夏昕_hibernate别名完成ResultSet和实体的映射
2010-12-13 17:09 1321p199
相关推荐
2018-04-16: Version 8.045a: Changed package metadata to include proper dependencies and restrictions 2018-02-08: Version 8.045: Support for more NIC models and VLAN tags 2015-01-16: Version 8.039.01...
To protect your rights, we need to make restrictions that forbid distributors to deny you these rights or to ask you to surrender these rights. These restrictions translate to certain ...
Fixed bug #77967 (Bypassing open_basedir restrictions via file uris). Standard: Fixed bug #77931 (Warning for array_map mentions wrong type). Fixed bug #78003 (strip_tags output change since ...
Dependencies and Restrictions Replaces/Updates: VMware built-in net-e1000e driver Depends On: vmkapi_2_0_0_0, com.vmware.driverAPI-9.2.0.0 Package Properties Requires MaintMode Live Install ...
SpEL Expression Conditions 46.4. Testing your Auto-configuration 46.4.1. Simulating a Web Context 46.4.2. Overriding the Classpath 46.5. Creating Your Own Starter 46.5.1. Naming 46.5.2. autoconfigure...
Dependencies and Restrictions Depends On: vmkapi_2_1_0_0, com.vmware.driverAPI-9.2.1.0 Compatible With: ESXi 5.0, ESXi 5.1, ESXi 5.5, ESXi 6.0, ESXi 6.5 Does NOT work With: ESXi 6.7 and newer ...
用于神经网络,深度学习方面的数据集。原网址因为The dataset is no longer available due to permission restrictions.
Dependencies and Restrictions Replaces: net-r8169 Compatible With: ESXi 5.1, ESXi 5.5, ESXi 6.0, ESXi 6.5 Does NOT work With: ESXi 6.7 and newer Package Properties Requires MaintMode Live Install...
2.4.5 Restrictions on the Multiplexed Stream Semantics 31 2.4.6 Constrained System Parameter Stream 33 1-ANNEX A (informative) 1 1-A.1 Overview 1 1-A.2 Encoder Operations 1 1-A.2.1 Degrees of freedom ...
2.4.5 Restrictions on the Multiplexed Stream Semantics 31 2.4.6 Constrained System Parameter Stream 33 1-ANNEX A (informative) 1 1-A.1 Overview 1 1-A.2 Encoder Operations 1 1-A.2.1 Degrees of freedom ...
which you currently reside may have restrictions on the import, possession, use, and/or re-export to another country, of encryption software. BEFORE using any encryption software, please check your...
Such restrictions are designed to ease implementation, assure conformity, facilitate interoperability, and ensure performance, in a manner tailored for PIV applications. The biometric data ...
Dynamic IP Restrictions: 保護 IIS 網站的流量守門員 iis 插件
7-Zip压缩软件7-Zip is open source software. Most of the source code is under the ... The unRAR code is under a mixed license: GNU LGPL + unRAR restrictions. Check license information here: 7-Zip license.
Such restrictions are designed to ease implementation, facilitate interoperability, and ensure performance, in a manner tailored for PIV applications. Keywords authentication; FIPS 201; identity ...
One of the main restrictions was that the control had to plot a lot of data and be able to display it quickly (on a Pocket PC). The control is able to do that by plotting only the new points of data,...
Do you have JavaScript experience but are ready to move away from the restrictions of web apps? Did you know that with Appcelerator you can use your existing web experience to build 100% native apps ...
which you currently reside may have restrictions on the import, possession, use, and/or re-export to another country, of encryption software. BEFORE using any encryption software, please check your...
FIPS 201 defines procedures for the PIV lifecycle... Such restrictions are designed to ease implementation, facilitate interoperability, and ensure performance, in a manner tailored for PIV applications.