hibernate删除对象:
1、jsp页面传入要删除的对象元素:
2、struts中配置:
/index.jsp
/test.jsp
3、在MessageAction中注入jsp传过来的数据到对象:元素有idfriend;username; fname;
public String execute() throws Exception {
Friend friend=new Friend();
friend.setUsername(this.getUsername());
friend.setFname(this.getFname());
friend.setIdfriend(this.getIdfriend());
new DelBiz(friend);
return SUCCESS;
}
public DelBiz(Friend friend) {
// TODO Auto-generated method stub
//使用hql删除;
configuration=new Configuration().configure();
sessionFactory=configuration.buildSessionFactory();
session=sessionFactory.openSession();
transaction=session.beginTransaction();
session.delete(friend);
transaction.commit();
session.close();
}