日期:2014-05-20 浏览次数:20723 次
/** * 自己写的更新记录函数 */ public boolean UpdateOperatorInfo(OperatorInfo operatorinfo){ boolean b=false; Session session=(Session) this.getSession(); Transaction tron=session.beginTransaction(); try{ OperatorInfo opinfo=new OperatorInfo(); session.load(opinfo, operatorinfo.getOperatorId()); opinfo.setOperatorName(operatorinfo.getOperatorName()); opinfo.setOperatorPwd(operatorinfo.getOperatorPwd()); opinfo.setIsAdmin(operatorinfo.getIsAdmin()); session.update(opinfo); //session.flush(); tron.commit(); b=true; }catch(HibernateException e){ if(tron!=null){ tron.rollback(); e.printStackTrace(); } }finally{ session.close(); } return b; }
<%@ page language="java" pageEncoding="utf-8" import="pojo.OperatorInfo,pojo.OperatorInfoDAO,java.util.Iterator"%> <%request.setCharacterEncoding("utf-8"); %> <% String s_id=request.getParameter("id"); String name=request.getParameter("name"); String pwd=request.getParameter("pwd"); String isno=request.getParameter("isno"); name=name.trim(); pwd=pwd.trim(); isno=isno.trim(); OperatorInfoDAO opdao=new OperatorInfoDAO(); OperatorInfo opinfo=new OperatorInfo(); opinfo.setOperatorId(Integer.parseInt(s_id)); opinfo.setIsAdmin(isno); opinfo.setOperatorName(name); opinfo.setOperatorPwd(pwd); //out.println(opinfo.getOperatorId()); if(opdao.UpdateOperatorInfo(opinfo)){ response.sendRedirect("addoperator.jsp"); }else{ out.println("你必须手动刷新一下本页才能更新成功,为什么,我也不知道"); } //opdao.attachDirty(opinfo); //response.sendRedirect("addoperator.jsp"); %>