您的位置:首页 > 其它

从网页中传入一个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();
}
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: 
相关文章推荐