⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 modifydepartmentsaction.java

📁 这是本人曾经在公司里用的,内部开发框架,基于struts+hibernate今天分享给大家
💻 JAVA
字号:
/**
 * 
 */
package cn.bway.admin.dept.action;

import javax.servlet.http.*;

import org.apache.struts.action.*;
import org.hibernate.Session;
import org.hibernate.Transaction;

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 ModifyDepartmentsAction extends BaseAction {

	/** 
	 * Method execute
	 * @param mapping
	 * @param form
	 * @param request
	 * @param response
	 * @return ActionForward
	 */
	public ActionForward execute(
		ActionMapping mapping,
		ActionForm form,
		HttpServletRequest request,
		HttpServletResponse response) {
		
		DepartmentsForm pForm = (DepartmentsForm) form;
		ActionErrors errors = new ActionErrors();
		String returnStr = WebConstant.FORWARD_SUCCESS;
		Session sess;
		Transaction tx=null;
		
		//����get����
		if(request.getMethod().equals("GET")){
			
			try {
				Departments Departments=(Departments) DepartmentsManagerFactory.getDepartmentsManager().getDepartments(request.getParameter("id"));
				pForm.setId(Departments.getId());
				pForm.setDeptname(Departments.getDeptname());
				pForm.setDeptdetail(Departments.getDeptdetail());
				pForm.setDeptlavel(Departments.getDeptlavel());
				pForm.setDeptmanager(Departments.getDeptmanager());
				
				request.setAttribute("staffid",Departments.getStaffid());
				request.setAttribute(WebConstant.PAGE_Object, pForm);
				returnStr = WebConstant.FORWARD_INITPAGE;
				return mapping.findForward(returnStr);
			} catch (NumberFormatException e) {
				// TODO Auto-generated catch block
				e.printStackTrace();
			} catch (BwayHibernateException e) {
				// TODO Auto-generated catch block
				e.printStackTrace();
			}
		}
		
		try {
			sess=HibernateSessionFactory.currentSession();
			tx=sess.beginTransaction();
			
			String staffid = request.getParameter("staffid");
			String deptmanager = Util.getStaffname(sess,staffid);
			
			saveObject(pForm,sess,deptmanager);
			
			tx.commit();
			
			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 deptmanager) throws BwayHibernateException{
		//�õ������Ͷ���
		Departments pvo=new Departments();
		pvo.setId(form.getId());
		pvo.setDeptname(form.getDeptname());
		pvo.setDeptlavel(form.getDeptlavel());
		pvo.setStaffid(form.getStaffid());
		
		pvo.setDeptdetail(form.getDeptdetail());
		pvo.setDeptmanager(deptmanager);
		
		sess.update(pvo);
		
//		DepartmentsManagerFactory.getDepartmentsManager().modfilyDepartments(pvo);
	}
	
}

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -