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

📄 u01mhelpaction.java

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

import java.util.List;


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.U01MHTypeBO;
import cn.hope.mana.bo.U01MHelpBO;
import cn.hope.mana.pojo.MHelp;
import cn.hope.mana.pojo.MHtype;

public class U01MHelpAction extends DispatchAction {
	Logger log = Logger.getLogger(U01MHelpAction.class.getName());

	private U01MHelpBO mHelpBO = new U01MHelpBO();
	public ActionForward search(ActionMapping mapping, ActionForm form,
			HttpServletRequest request, HttpServletResponse response)
			throws Exception {
		ActionMessages errors = new ActionMessages();
		List list = null;
		try {
			List htList = new U01MHTypeBO().searchAll();// 获得帮助分类列表
			list = mHelpBO.search();
			request.getSession().setAttribute("rs",list);
			request.getSession().setAttribute("htype",htList);
		}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 insert(ActionMapping mapping, ActionForm form,
			HttpServletRequest request, HttpServletResponse response)
			throws Exception {
		ActionMessages errors = new ActionMessages();
		DynaValidatorForm mhForm = (DynaValidatorForm) form;
		MHelp mHelp = (MHelp)mhForm.get("mHelp");
		MHtype mHtype = (MHtype)mhForm.get("mHtype");
		try {
			if(!mHelpBO.insert(mHelp,mHtype)){
				errors.add("error", new ActionMessage(
				"errors.U01MHelpForm.HTitle.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 helpForm = (DynaValidatorForm) form;
		MHelp help = (MHelp)helpForm.get("mHelp");
		try {
			mHelpBO.delete(help);
		}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 find(ActionMapping mapping, ActionForm form,
			HttpServletRequest request, HttpServletResponse response)
			throws Exception {
		ActionMessages errors = new ActionMessages();
		Integer hid = Integer.valueOf(request.getParameter("hId"));
		MHelp mHelp = new MHelp();
		MHtype mHtype = new MHtype();
		DynaValidatorForm mHelpForm = (DynaValidatorForm) form;
		try {
			mHelp = mHelpBO.find(hid);
			mHtype = mHelp.getMHtype();
			mHelpForm.set("mHelp",mHelp);
			mHelpForm.set("mHtype",mHtype);
		}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("success1");
	}
	public ActionForward update(ActionMapping mapping, ActionForm form,
			HttpServletRequest request, HttpServletResponse response)
			throws Exception {
		ActionMessages errors = new ActionMessages();
		DynaValidatorForm mhForm = (DynaValidatorForm) form;
		MHelp mHelp = (MHelp)mhForm.get("mHelp");
		MHtype mHtype = (MHtype)mhForm.get("mHtype");
		try {
			if(!mHelpBO.update(mHelp,mHtype)){
				errors.add("error", new ActionMessage(
				"errors.U01MHelpForm.HTitle.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");
	}

}

⌨️ 快捷键说明

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