hibernate qbc教程
- 作者: 已被封号段友再见
- 来源: 51数据库
- 2021-01-02
QBC查询会根据传入的实体的属性经行查找,当然会忽略主键,关联属性。
User u = new User();
u.setAge(20),
u.setSex("男"),
使用QBC就如同会发送如下sql语句:
select * from user wher age=20 and sex='男';
作用就是根据条件得到相应的实体
public List findByExample(UserForm instance) {
log.debug("finding UserForm instance by example");
try {
List results = hibernateTemplate.findByExample(instance);
log.debug("find by example successful, result size: "
+ results.size());
return results;
} catch (RuntimeException re) {
log.error("find by example failed", re);
throw re;
}
}
在调用的时候直接传递一个UserForm的对象就可以啊
User u = new User();
u.setAge(20),
u.setSex("男"),
使用QBC就如同会发送如下sql语句:
select * from user wher age=20 and sex='男';
作用就是根据条件得到相应的实体
public List findByExample(UserForm instance) {
log.debug("finding UserForm instance by example");
try {
List results = hibernateTemplate.findByExample(instance);
log.debug("find by example successful, result size: "
+ results.size());
return results;
} catch (RuntimeException re) {
log.error("find by example failed", re);
throw re;
}
}
在调用的时候直接传递一个UserForm的对象就可以啊
推荐阅读
