assettypedispatchaction.java

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

JAVA
154
字号
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.AssetTypeDAO;
import com.qrsx.appcam.form.AssetTypeForm;
import com.qrsx.appcam.model.AssetType;

public class AssetTypeDispatchAction 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");
		}
		// 获取表单上输入的信息,并把这些信息复制到AssetType对象中去
		AssetTypeForm typeForm = (AssetTypeForm) form;
		AssetType assetType = new AssetType();
		BeanUtils.copyProperties(assetType, form);

		AssetTypeDAO dao = new AssetTypeDAO();
		// 判断资产类型Id是否为空,若为空则执行创建操作,否则执行更新
		if (typeForm.getId() == null || typeForm.getId().trim().length() == 0) {
			dao.create(assetType);
			saveMessage(request, "assetTypeForm.added", assetType.getName());
		} else {
			dao.update(assetType);
			saveMessage(request, "assetTypeForm.updated", assetType.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) {
			AssetTypeDAO dao = new AssetTypeDAO();
			// 获取编辑对象
			AssetType assetType = dao.findById(Integer.valueOf(id));
			if (assetType != null) {
				// 把获取的编辑对象信息复制表单中
				BeanUtils.copyProperties(form, assetType);
			}
		}

		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) {
			AssetTypeDAO dao = new AssetTypeDAO();
			dao.delete(Integer.valueOf(id));
			saveMessage(request, "assetTypeForm.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);
		AssetType assetType = new AssetType();
		//获取查询条件,把表单中的信息复制到assetType对象中
		BeanUtils.copyProperties(assetType, form);

		AssetTypeDAO dao = new AssetTypeDAO();
		//执行检索操作
		List<AssetType> list = dao.list(assetType);
		//把检索到的数据返回list页面
		request.setAttribute("assetTypes", 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);
		AssetTypeDAO dao = new AssetTypeDAO();
		//执行检索操作,并把数据返回到list页面
		List<AssetType> list = dao.findAll();

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

}

⌨️ 快捷键说明

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