addtypedispatchaction.java

来自「struts做得固定资产管理系统 带毕业论文完整版」· Java 代码 · 共 156 行

JAVA
156
字号
package com.qrsx.appcam.action;

import java.util.List;

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

import org.apache.commons.beanutils.BeanUtils;
import org.apache.struts.action.ActionErrors;
import org.apache.struts.action.ActionForm;
import org.apache.struts.action.ActionForward;
import org.apache.struts.action.ActionMapping;
import com.qrsx.appcam.dao.AddTypeDAO;
import com.qrsx.appcam.form.AddTypeForm;
import com.qrsx.appcam.model.AddType;

public class AddTypeDispatchAction extends BaseDispatchAction {

	/**
	 * 保存信息:更新、创建
	 * 
	 * @param mapping
	 * @param form
	 * @param request
	 * @param response
	 * @return
	 */
	public ActionForward save(ActionMapping mapping, ActionForm form,
			HttpServletRequest request, HttpServletResponse response)
			throws Exception {
		BaseDispatchAction.isLogon(request, response);//验证用户是否已经登陆
		// 验证数据有效性,如果验证不成功再返回编辑界面
		ActionErrors errors = form.validate(mapping, request);
		if (!errors.isEmpty()) {
			saveErrors(request, errors);
			return mapping.findForward("edit");
		}
		//获取表单信息
		AddTypeForm addTypeForm = (AddTypeForm) form;
		AddType addType = new AddType();
		//把获取的表单的信息,复制到addtype中
		BeanUtils.copyProperties(addType, form);

		AddTypeDAO dao = new AddTypeDAO();
		//如果资产增加类型编号为空则创建,否则为更新
		if (addTypeForm.getId() == null || addTypeForm.getId().trim().length() == 0) {
			dao.create(addType);
			saveMessage(request, "addTypeForm.added", addTypeForm.getName());
		} else {
			dao.update(addType);
			saveMessage(request, "addTypeForm.updated", addTypeForm.getName());
		}
		return mapping.findForward("success");
	}

	/**
	 * 编辑信息:进入新建页面、进入更新页面
	 * 
	 * @param mapping
	 * @param form
	 * @param request
	 * @param response
	 * @return
	 */
	public ActionForward edit(ActionMapping mapping, ActionForm form,
			HttpServletRequest request, HttpServletResponse response)
			throws Exception {
		BaseDispatchAction.isLogon(request, response);//验证用户是否已经登陆
		
		String id = request.getParameter("id");

		if (id != null && id.trim().length() > 0) {
			
			AddTypeDAO dao = new AddTypeDAO();	
			//获取要编辑的对象信息
			AddType addType = dao.findById(Integer.valueOf(id));
			if (addType != null) {
				//把获取到的对象信息复制到form中去
				BeanUtils.copyProperties(form, addType);
			}
		}
		return mapping.findForward("edit");
	}

	/**
	 * 删除信息
	 * 
	 * @param mapping
	 * @param form
	 * @param request
	 * @param response
	 * @return
	 */
	public ActionForward delete(ActionMapping mapping, ActionForm form,
			HttpServletRequest request, HttpServletResponse response)
			throws Exception {
		BaseDispatchAction.isLogon(request, response);//验证用户是否已经登陆
		String id = request.getParameter("id");
		//如果获取的Id不为空,则执行删除操作
		if (id != null && id.trim().length() > 0) {
			
			AddTypeDAO dao = new AddTypeDAO();
			//执行删除
			dao.delete(Integer.valueOf(id));			
			saveMessage(request, "addTypeForm.deleted");
		}
		return mapping.findForward("success");
	}

	/**
	 * 动态检索信息
	 * 
	 * @param mapping
	 * @param form
	 * @param request
	 * @param response
	 * @return
	 * @throws Exception
	 */
	public ActionForward list(ActionMapping mapping, ActionForm form,
			HttpServletRequest request, HttpServletResponse response)
			throws Exception {
		BaseDispatchAction.isLogon(request, response);//验证用户是否已经登陆
		//获取检索条件
		AddType addType = new AddType();
		BeanUtils.copyProperties(addType, form);
		//进行检索
		AddTypeDAO dao = new AddTypeDAO();
		List<AddType> list = dao.list(addType);
		//把检索的信息返回到页面中
		request.setAttribute("addTypes", list);
		return mapping.findForward("list");
	}

	/**
	 * 检索所有的增加方式
	 * 
	 * @param mapping
	 * @param form
	 * @param request
	 * @param response
	 * @return
	 * @throws Exception
	 */
	public ActionForward findAll(ActionMapping mapping, ActionForm form,
			HttpServletRequest request, HttpServletResponse response)
			throws Exception {
		BaseDispatchAction.isLogon(request, response);//验证用户是否已经登陆
		AddTypeDAO dao = new AddTypeDAO();
		List<AddType> list = dao.findAll();

		request.setAttribute("addTypes", list);
		return mapping.findForward("list");
	}
}

⌨️ 快捷键说明

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