org.springframework.orm.hibernate3.HibernateTemplate.findByExample(Object exampleEntity)
这个方法按照exampleEntity所设置的属性值来组合查询语句的where条件,比如:
|
这样where条件就是:
|
如果再加上下面这句
|
那么where条件就是:
|
所以,在使用时要注意上面的用法。
同时,还有一个重载的方法
findByExample(
Object exampleEntity,int firstResult,int maxResults)
这个方法从第firstResult-1个记录开始查询,一共查询maxResults个记录。为什么是从firstResult-1开始呢?因为和数组一样,他认为一个记录的下标是0.
这个时候的SQL条件为:
findByExample()使用时得出结论:
1.不支持主键
2.不支持关联
3.不支持NULL
- 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