实现修改学生资料action和页面调用
业务逻辑代码:
public boolean updateStudent(Student stu) {
Transaction transaction=null;
try{
Session session=MyHibernateSessionFactory.getSessionFactory().getCurrentSession();
transaction=session.beginTransaction();
session.update(stu);;
transaction.commit();
return true;
}catch(Exception e){
e.printStackTrace();
return false;
}finally{
if(transaction!=null){
transaction=null;
}
}
}
action代码:
public String save() throws ParseException{
Student stu=new Student();
stu.setSid(request.getParameter("sid"));
stu.setSname(request.getParameter("sname"));
stu.setGender(request.getParameter("gender"));
SimpleDateFormat sdf=new SimpleDateFormat("yyyy-MM-dd");
stu.setBirthday(sdf.parse(request.getParameter("birthday")));
stu.setAddress(request.getParameter("address"));
StudentDao sd=new StudentDaoImpl();
sd.updateStudent(stu);
return "save_success";
}