📄 xxaction.java
字号:
package com.relationinfo.webapp.action;import javax.servlet.http.HttpServletRequest;import javax.servlet.http.HttpServletResponse;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 com.relationinfo.Constants;import com.relationinfo.model.Xx;import com.relationinfo.service.XxManager;import com.relationinfo.webapp.form.XxForm;/** * Action class to handle CRUD on a Xx object * * @struts.action name="xxForm" path="/xxs" scope="request" * validate="false" parameter="method" input="mainMenu" * @struts.action name="xxForm" path="/editXx" scope="request" * validate="false" parameter="method" input="list" * @struts.action name="xxForm" path="/saveXx" scope="request" * validate="true" parameter="method" input="edit" * * @struts.action-forward name="edit" path="/WEB-INF/pages/xxForm.jsp" * @struts.action-forward name="list" path="/WEB-INF/pages/xxList.jsp" * @struts.action-forward name="search" path="/xxs.html" redirect="true" */public final class XxAction extends BaseAction { public ActionForward cancel(ActionMapping mapping, ActionForm form, HttpServletRequest request, HttpServletResponse response) throws Exception { return mapping.findForward("search"); } public ActionForward delete(ActionMapping mapping, ActionForm form, HttpServletRequest request, HttpServletResponse response) throws Exception { if (log.isDebugEnabled()) { log.debug("Entering 'delete' method"); } ActionMessages messages = new ActionMessages(); XxForm xxForm = (XxForm) form; // Exceptions are caught by ActionExceptionHandler XxManager mgr = (XxManager) getBean("xxManager"); mgr.removeXx(xxForm.getXxbm()); messages.add(ActionMessages.GLOBAL_MESSAGE, new ActionMessage("xx.deleted")); // save messages in session, so they'll survive the redirect saveMessages(request.getSession(), messages); return mapping.findForward("search"); } public ActionForward edit(ActionMapping mapping, ActionForm form, HttpServletRequest request, HttpServletResponse response) throws Exception { if (log.isDebugEnabled()) { log.debug("Entering 'edit' method"); } XxForm xxForm = (XxForm) form; // if an id is passed in, look up the user - otherwise // don't do anything - user is doing an add if (xxForm.getXxbm() != null) { XxManager mgr = (XxManager) getBean("xxManager"); Xx xx = mgr.getXx(xxForm.getXxbm()); xxForm = (XxForm) convert(xx); updateFormBean(mapping, request, xxForm); } return mapping.findForward("edit"); } public ActionForward save(ActionMapping mapping, ActionForm form, HttpServletRequest request, HttpServletResponse response) throws Exception { if (log.isDebugEnabled()) { log.debug("Entering 'save' method"); } // Extract attributes and parameters we will need ActionMessages messages = new ActionMessages(); XxForm xxForm = (XxForm) form; boolean isNew = ("".equals(xxForm.getXxbm()) || xxForm.getXxbm() == null); XxManager mgr = (XxManager) getBean("xxManager"); Xx xx = (Xx) convert(xxForm); mgr.saveXx(xx); // add success messages if (isNew) { messages.add(ActionMessages.GLOBAL_MESSAGE, new ActionMessage("xx.added")); // save messages in session to survive a redirect saveMessages(request.getSession(), messages); return mapping.findForward("search"); } else { messages.add(ActionMessages.GLOBAL_MESSAGE, new ActionMessage("xx.updated")); saveMessages(request, messages); return mapping.findForward("edit"); } } public ActionForward search(ActionMapping mapping, ActionForm form, HttpServletRequest request, HttpServletResponse response) throws Exception { if (log.isDebugEnabled()) { log.debug("Entering 'search' method"); } XxForm xxForm = (XxForm) form; Xx xx = (Xx) convert(xxForm); XxManager mgr = (XxManager) getBean("xxManager"); request.setAttribute(Constants.XX_LIST, mgr.getXxs(xx)); return mapping.findForward("list"); } public ActionForward unspecified(ActionMapping mapping, ActionForm form, HttpServletRequest request, HttpServletResponse response) throws Exception { return search(mapping, form, request, response); }}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -