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

📄 u01cdeptaction.java

📁 持久层hibernate技术使用的一个例子
💻 JAVA
字号:
package cn.hope.mana.action;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import org.apache.log4j.Logger;
import org.apache.struts.action.ActionForm;
import org.apache.struts.action.ActionForward;
import org.apache.struts.action.ActionMapping;
import org.apache.struts.action.ActionMessage;
import org.apache.struts.action.ActionMessages;
import org.apache.struts.actions.DispatchAction;
import org.apache.struts.validator.DynaValidatorForm;

import cn.hope.mana.bo.U01CDeptBO;
import cn.hope.mana.pojo.CDept;

public class U01CDeptAction extends DispatchAction {
	Logger log = Logger.getLogger(U01CDeptAction.class.getName());
	
	private U01CDeptBO deptBO = new U01CDeptBO();
	public ActionForward search(ActionMapping mapping, ActionForm form,
			HttpServletRequest request, HttpServletResponse response)
			throws Exception {
		ActionMessages errors = new ActionMessages();
		String dIdStr = request.getParameter("deptId");
		DynaValidatorForm deptForm = (DynaValidatorForm) form;
		try {
			if (dIdStr != null) {
				Integer dId = Integer.valueOf(dIdStr.trim());
				CDept dept = deptBO.search(dId);
				request.getSession().setAttribute("cDept",dept);
				return mapping.findForward("update");
			}
			request.getSession().setAttribute("deptList",deptBO.search());
			deptForm.set("cdept",new CDept());
			return mapping.findForward("success");
		}catch (Exception e) {
			log.error(e);
			e.printStackTrace();
			ActionMessage am = new ActionMessage(e.toString());
			errors.add(ActionMessages.GLOBAL_MESSAGE, new ActionMessage(
					"errors.u07exception"));
			errors.add(ActionMessages.GLOBAL_MESSAGE, am);
			saveErrors(request, errors);
			return mapping.findForward("errorPage");
		}
	}
	
	public ActionForward insert(ActionMapping mapping, ActionForm form,
			HttpServletRequest request, HttpServletResponse response)
			throws Exception {
		ActionMessages errors = new ActionMessages();
		DynaValidatorForm deptForm = (DynaValidatorForm) form;
		CDept cDept = (CDept)deptForm.get("cdept");
		try {
			if (!deptBO.insert(cDept)) {
				errors.add("error",new ActionMessage(
						"errors.U01CDeptForm.dName.haved"));
				saveErrors(request,errors);
				return mapping.findForward("error");
			}
		}catch (Exception e) {
			log.error(e);
			e.printStackTrace();
			ActionMessage am = new ActionMessage(e.toString());
			errors.add(ActionMessages.GLOBAL_MESSAGE, new ActionMessage(
					"errors.u07exception"));
			errors.add(ActionMessages.GLOBAL_MESSAGE, am);
			saveErrors(request, errors);
			return mapping.findForward("errorPage");			
		}
		return mapping.findForward("success");
	}
	
	public ActionForward update(ActionMapping mapping, ActionForm form,
			HttpServletRequest request, HttpServletResponse response)
			throws Exception {
		ActionMessages errors = new ActionMessages();
		String deptId = request.getParameter("DId");
		DynaValidatorForm deptForm = (DynaValidatorForm) form;
		CDept cDept = (CDept)deptForm.get("cdept");
		cDept.setDId(Integer.valueOf(deptId));
		try {
			if (!deptBO.update(cDept)) {
				errors.add("error",new ActionMessage(
						"errors.U01CDeptForm.dName.haved"));
				saveErrors(request,errors);
				return mapping.findForward("error");
			}
		}catch (Exception e) {
			log.error(e);
			e.printStackTrace();
			ActionMessage am = new ActionMessage(e.toString());
			errors.add(ActionMessages.GLOBAL_MESSAGE, new ActionMessage(
					"errors.u07exception"));
			errors.add(ActionMessages.GLOBAL_MESSAGE, am);
			saveErrors(request, errors);
			return mapping.findForward("errorPage");			
		}
		return mapping.findForward("success");
	}
	
	public ActionForward delete(ActionMapping mapping, ActionForm form,
			HttpServletRequest request, HttpServletResponse response)
			throws Exception {
		ActionMessages errors = new ActionMessages();
		DynaValidatorForm deptForm = (DynaValidatorForm) form;
		CDept cDept = (CDept)deptForm.get("cdept");
		try {
			if (!deptBO.delete(cDept)) {
				errors.add("error",new ActionMessage(
						"errors.U01CDeptForm.sub.error"));
				saveErrors(request,errors);
				return mapping.findForward("error");
			}
		}catch (Exception e) {
			log.error(e);
			e.printStackTrace();
			ActionMessage am = new ActionMessage(e.toString());
			errors.add(ActionMessages.GLOBAL_MESSAGE, new ActionMessage(
					"errors.u07exception"));
			errors.add(ActionMessages.GLOBAL_MESSAGE, am);
			saveErrors(request, errors);
			return mapping.findForward("errorPage");			
		}
		return mapping.findForward("success");
	}

}

⌨️ 快捷键说明

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