storagedispatchaction.java
来自「struts做得固定资产管理系统 带毕业论文完整版」· Java 代码 · 共 149 行
JAVA
149 行
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.StorageDAO;
import com.qrsx.appcam.form.StorageForm;
import com.qrsx.appcam.model.Storage;
public class StorageDispatchAction 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");
}
// 获取表单的数据:把表单的数据映射到对象中去
StorageForm storageForm = (StorageForm) form;
Storage storage = new Storage();
BeanUtils.copyProperties(storage, form);
StorageDAO dao = new StorageDAO();
// 判断对象Id是否为空,若为空则执行创建操作,否则执行更新操作
if (storageForm.getId() == null
|| storageForm.getId().trim().length() == 0) {
dao.create(storage);
saveMessage(request, "storageForm.added", storageForm.getName());
} else {
dao.update(storage);
saveMessage(request, "storageForm.updated", storageForm.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) {
StorageDAO dao = new StorageDAO();
// 获取编辑对象
Storage storage = dao.findById(Integer.valueOf(id));
if (storage != null) {
// 把要编辑对象的数据映射到表单中
BeanUtils.copyProperties(form, storage);
}
}
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");
if (id != null && id.trim().length() > 0) {
StorageDAO dao = new StorageDAO();
dao.delete(Integer.valueOf(id));// 执行删除操作
saveMessage(request, "storageForm.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);//验证用户是否已经登陆
// 把输入的检索条件,映射到对象中去
Storage storage = new Storage();
BeanUtils.copyProperties(storage, form);
// 执行检索操作,并把检索到的结果返回到编辑页面
StorageDAO dao = new StorageDAO();
List<Storage> list = dao.list(storage);
request.setAttribute("storages", 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);//验证用户是否已经登陆
StorageDAO dao = new StorageDAO();
List<Storage> list = dao.findAll();
request.setAttribute("storages", list);
return mapping.findForward("list");
}
}
⌨️ 快捷键说明
复制代码Ctrl + C
搜索代码Ctrl + F
全屏模式F11
增大字号Ctrl + =
减小字号Ctrl + -
显示快捷键?