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

📄 u01mhtypeaction.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.U01MHTypeBO;
import cn.hope.mana.pojo.MHtype;

public class U01MHtypeAction extends DispatchAction {

	Logger log = Logger.getLogger(U01MHtypeAction.class.getName());
	
	private U01MHTypeBO htBO = new U01MHTypeBO();
	public ActionForward search(ActionMapping mapping, ActionForm form,
			HttpServletRequest request, HttpServletResponse response)
			throws Exception {
		ActionMessages errors = new ActionMessages();
		try{
			String htId = request.getParameter("htId");
			MHtype mHtype = htBO.find(Integer.valueOf(htId));
			request.getSession().setAttribute("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("success");
	}

	public ActionForward update(ActionMapping mapping, ActionForm form,
			HttpServletRequest request, HttpServletResponse response)
			throws Exception {
		ActionMessages errors = new ActionMessages();
		DynaValidatorForm htypeForm = (DynaValidatorForm) form;
		String htId = request.getParameter("htId");
		MHtype mHtype = (MHtype)htypeForm.get("mHtype");
		mHtype.setHtId(Integer.valueOf(htId));
		mHtype.setFlag("0");
		try{
			if(!htBO.update(mHtype)) {
				errors.add("error", new ActionMessage(
				"errors.U01MHtypeForm.htName.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();
		String htId = request.getParameter("htId");
		try{
			htBO.delete(Integer.valueOf(htId));
		}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 + -