从网页中传入一个Id 通过Id 删除或者查询
2014-10-27 19:37
465 查看
如果要用Id 查询,删除的话
hibernatebaseDao中是
// 查询单个
public Object queryOne(String claName, int id) {
Session session = HibernateSessionFactory.getSession();
Object o = session.get(claName, id);
HibernateSessionFactory.closeSession();
return o;
}
// 根据ID删除
public void deleteById(String claName, int id) {
Session session = HibernateSessionFactory.getSession();
// 先根据ID查询出来
Object o = session.get(claName, id);
session.delete(o);
HibernateSessionFactory.closeSession();
}
列: 如果一个User到 要通过,查询,删除就可以用下面的方法
// 查询传入Id
public HouseInfo queryTitle(HouseInfo houseInfo) {
this.queryOne("com.scme.Entityt.HouseInfo", houseInfo.getHouseId());
return HouseInfo) this.queryOne("com.scme.Entityt.HouseInfo", houseInfo.getHouseId());
}
// 根据ID删除
public void deleteById(String claName, int id) {
Session session = HibernateSessionFactory.getSession();
// 先根据ID查询出来
Object o = session.get(claName, id);
session.delete(o);
HibernateSessionFactory.closeSession();
}
hibernatebaseDao中是
// 查询单个
public Object queryOne(String claName, int id) {
Session session = HibernateSessionFactory.getSession();
Object o = session.get(claName, id);
HibernateSessionFactory.closeSession();
return o;
}
// 根据ID删除
public void deleteById(String claName, int id) {
Session session = HibernateSessionFactory.getSession();
// 先根据ID查询出来
Object o = session.get(claName, id);
session.delete(o);
HibernateSessionFactory.closeSession();
}
列: 如果一个User到 要通过,查询,删除就可以用下面的方法
// 查询传入Id
public HouseInfo queryTitle(HouseInfo houseInfo) {
this.queryOne("com.scme.Entityt.HouseInfo", houseInfo.getHouseId());
return HouseInfo) this.queryOne("com.scme.Entityt.HouseInfo", houseInfo.getHouseId());
}
// 根据ID删除
public void deleteById(String claName, int id) {
Session session = HibernateSessionFactory.getSession();
// 先根据ID查询出来
Object o = session.get(claName, id);
session.delete(o);
HibernateSessionFactory.closeSession();
}
相关文章推荐
- 通过一个表的id同时查询多个表的数据
- mysql查询根据一个字段或者两个字段内容重复的记录并将其全部删除
- sqlserver 根据一个泛型id查询数据,批量删除数据
- Winform中通过一个字符串定位到和字符串相等ID的控件(将字符串转换成相应的控件名称)
- 新写的一个使用ASP.NET AJAX中的UpdatePanel控件实现GridView的无刷新删除,更新,添加,查询!
- 查询表中已删除id的方法
- 通过js脚本复制网页上的一个表格的不错实现方法
- 最近在编一个通过代理实现网页模拟点击和POST的Internet程序
- 通过一个按钮删除我在ListCtrl中选的一项
- asp中 打开网页时出现“操作必须使用一个可更新的查询”原因及解决办法
- ADO的一次开发实践(vc通过ADO连接access数据库做的一个多功能查询系统)
- 在table中通过按钮添加一行或者删除一行
- SAP ABAP/4学习---如何给写好的一个程序分配事务代码,用户可以直接通过事务码来访问程序.或者加入收藏夹(9)
- asp+access中 打开网页时出现“操作必须使用一个可更新的查询”原因及解决办法
- ADODB.Recordset 错误 '800a0bcd' BOF 或 EOF 中有一个是“真”,或者当前的记录已被删除,所需的操作要求一个当前的记录。
- 通过链接服务器查询视图得到“意外的Null值(MessageID:7342)”错误的处理方法
- 通过一个结构体或者普通指针来调用一个带有虚拟函数的对象
- 通过JavaScript脚本复制网页上的一个表格
- 一个传入查询的存储过程
- 不用ID实现一个事件通过多个观察者