使用Spring封装的Hibernate findByExample方法
来源:互联网 发布:js打砖块游戏图片素材 编辑:程序博客网 时间:2024/06/05 05:53
org.springframework.orm.hibernate3.HibernateTemplate.findByExample(Object exampleEntity)
这个方法按照exampleEntity所设置的属性值来组合查询语句的where条件,比如:
Users anUser= new Users();
anUser.setUserName("a");
anUser.setPassWord("b");
这样where条件就是:
where username='a'and password='b'
如果再加上下面这句
anUser.setRealName("");
那么where条件就是:
where username='a'and password='b'and realname=''
所以,在使用时要注意上面的用法。
同时,还有一个重载的方法findByExample(Object exampleEntity,int firstResult,int maxResults)
这个方法从第firstResult-1个记录开始查询,一共查询maxResults个记录。为什么是从firstResult-1开始呢?因为和数组一样,他认为一个记录的下标是0.
这个时候的SQL条件为:
findByExample()使用时得出结论:
1.不支持主键
2.不支持关联
3.不支持NULL
Hibernate/Spring的findByExample
- Class User{
- String username;
- String password = "默认口令";
- Company company;
- getter()&setter().....
- }
- Company company = companyDao.getById("id");
- User user = new User();
- user.setSid("主键");
- uer.setUsername("user");
- use.setCompany(company);
- userDao.findByExample(user);
这个时候的SQL条件为:
- select * from user
- where username = ?
- and password = ?
findByExample()使用时得出结论:
1.不支持主键
2.不支持关联
3.不支持NULL
引用
Version properties, identifiers and associations are ignored. By default, null valued properties are excluded
0 0
- 使用Spring封装的Hibernate findByExample方法
- Hibernate/Spring的findByExample
- 关于使用Hibernate findByExample的注意事项
- hibernate的findByExample
- hibernate的findByExample
- hibernate的findByExample
- hibernate的findByExample
- hibernate的findByExample
- Spring HibernateTemplate findByExample 方法 BUG。
- Hibernate中的DAO操作的findByExample
- hibernate中用findByExample方法出现Unknown entity: XXX异常
- hibernate findbyexample findbycriteria
- Hibernate 的 findByExample 用法需要注意的地方
- findByExample
- findByExample
- Spring中Hibernate的事务封装
- 浅谈spring对hibernate的封装
- Spring对Hibernate DAO的封装
- MySql查询系统时间,SQLServer查询系统时间,Oracle查询系统时间
- JSP中页面跳转response.sendRedirect()和request.getRequestDispatcher()的区别
- delete引起的debug错误(有关内存释放的一些问题)
- Prometheus 实战于源码分析之collector
- 神经网络:比原来更容易学习了
- 使用Spring封装的Hibernate findByExample方法
- WMS系统
- 解析MP4文件中的sps和pps
- Shader编程学习笔记(八)—— Surface Shader 2
- C/C++函数形参传实参时值传递、指针传递、引用传递的区别
- spring中普通类如何获取session,request等对象
- source insight 下设置tab键的宽度
- Window 7下安装python等
- itk反向配准失败的问题