1。action类中的方法:
public ActionForward updateRegister(ActionMapping mapping,ActionForm form,HttpServletRequest req,
HttpServletResponse res)throws Exception{
MyRegisterInfo register = new MyRegisterInfo();
MyRegisterActionForm registerForm = (MyRegisterActionForm) form;
this.beanCopy(register,form);
MyRegisterService service = (MyRegisterService) this.getBean("myRegisterService");
if (service.updateRegister(register))
{
PageInfo page = new PageInfo(req.getParameterMap());
req.setAttribute("registerList",service.listRegister(page));
return mapping.findForward("list-ok");
}
2。sevice中的方法体为
public boolean updateRegister(MyRegisterInfo myRegisterInfo)
{
MyRegisterDAO dao = (MyRegisterDAO) this.getBaseDAO();
dao.update(myRegisterInfo);
return true;
}
3。dao中的方法体为
public void update(Object obj) {
getHibernateTemplate().saveOrUpdate(obj);
}
4。因为registerform的类为四个属性的getter和setter
private String name;
private String password;
private String repassword;
private Long id;
//一开始因为少了id,从页面上传来的form没有id,调用saveOrUpdate()方法时,hibernate调用的sql语句是insert,而不是update语句,因此页面上原来的行不仅还在,而且还不断有新行增加。
posted on 2006-04-14 16:16
aimy 阅读(223)
评论(0) 编辑 收藏