📄 adddepartmentsaction.java
字号:
/**
*
*/
package cn.bway.admin.dept.action;
import javax.servlet.http.*;
import org.apache.struts.action.*;
import org.hibernate.Session;
import cn.bway.admin.dept.form.DepartmentsForm;
import cn.bway.admin.dept.impl.DepartmentsManagerFactory;
import cn.bway.admin.dept.model.Departments;
import cn.bway.common.BwayHibernateException;
import cn.bway.common.Util;
import cn.bway.common.WebConstant;
import cn.bway.common.action.BaseAction;
import cn.bway.common.dao.HibernateSessionFactory;
/**
* @author Kson
*
*/
public class AddDepartmentsAction extends BaseAction {
/**
* Method execute
* @param mapping
* @param form
* @param request
* @param response
* @return ActionForward
* @throws Exception
*/
public ActionForward execute(ActionMapping mapping,
ActionForm form,HttpServletRequest request, HttpServletResponse response)
throws BwayHibernateException {
DepartmentsForm pForm = (DepartmentsForm) form;
ActionErrors errors = new ActionErrors();
String returnStr = WebConstant.FORWARD_SUCCESS;
Session sess;
//处理get请求����get����
if(request.getMethod().equals("GET")){
request.setAttribute(WebConstant.PAGE_Object, pForm);
returnStr = WebConstant.FORWARD_INITPAGE;
return mapping.findForward(returnStr);
}
try {
sess=HibernateSessionFactory.currentSession();
String staffid = request.getParameter("staffid");
String deptmanager = Util.getStaffname(sess,staffid);
saveObject(pForm,sess,deptmanager);
returnStr=WebConstant.FORWARD_SUCCESS;
request.setAttribute(WebConstant.RETURN_Message,"添加成功!");
} catch (BwayHibernateException e) {
returnStr=WebConstant.FORWARD_FAIL;
errors.add(ActionErrors.GLOBAL_ERROR,new ActionError("edu.system.excption",e.getMessage()));
this.saveErrors(request,errors);
e.printStackTrace();
}finally{
HibernateSessionFactory.closeSession();
}
return mapping.findForward(returnStr);
}
/**
* 构建VO,保存对象�������
* @throws BwayHibernateException
*/
private void saveObject(DepartmentsForm form,Session sess,String staffname) throws BwayHibernateException{
//得到父类型对象�õ������Ͷ���
Departments pvo=new Departments();
pvo.setDeptname(form.getDeptname());
pvo.setDeptlavel(form.getDeptlavel());
pvo.setStaffid(form.getStaffid());
pvo.setDeptmanager(staffname);
pvo.setDeptdetail(form.getDeptdetail());
sess.save(pvo);
// DepartmentsManagerFactory.getDepartmentsManager().addDepartments(pvo);
}
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -