📄 storageaction.java
字号:
package com.qrsx.asset.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.asset.dao.StorageDAO;import com.qrsx.asset.form.StorageForm;import com.qrsx.asset.model.Storage;public class StorageAction extends BaseAction{ /** * 创建,更新仓库信息 */ public ActionForward save( ActionMapping mapping, ActionForm form, HttpServletRequest request, HttpServletResponse response)throws Exception{ ActionErrors errors = form.validate(mapping, request); if(!errors.isEmpty()){ saveErrors(request,errors); return mapping.findForward("edit"); } StorageForm storageForm = (StorageForm)form; Storage storage = new Storage(); StorageDAO dao = new StorageDAO(); BeanUtils.copyProperties(storage,storageForm); if(storage.getId()==null||storage.getId()==0){ dao.create(storage); saveMessage(request,"assetStorageForm.added",storage.getName()); }else{ dao.update(storage); saveMessage(request,"assetStorageForm.updated",storage.getName()); } return mapping.findForward("success"); } /** * 编辑仓库信息 */ public ActionForward edit( ActionMapping mapping, ActionForm form, HttpServletRequest request, HttpServletResponse response)throws Exception{ String id = request.getParameter("id"); StorageDAO dao = new StorageDAO(); if(id!=null&&id.trim().length()>0){ Storage storage = dao.findById(Integer.valueOf(id)); if(storage != null){ BeanUtils.copyProperties(form, storage); } } return mapping.findForward("edit"); } /** * 动态检索仓库信息 */ public ActionForward list( ActionMapping mapping, ActionForm form, HttpServletRequest request, HttpServletResponse response)throws Exception{ String page = request.getParameter("currentpage"); Integer currentpage=1; if(page!=null){ currentpage=Integer.valueOf(page); } StorageForm storageform = (StorageForm)form; Storage storage = new Storage(); BeanUtils.copyProperties(storage, storageform); StorageDAO dao = new StorageDAO(); //获取显式传递过来的name值,若不空则转码,并设为assetType的值 String name=request.getParameter("na"); if(name!=null){ name=new String (name.getBytes("ISO-8859-1"),"gb2312" ); storage.setName(name); } Object[] object = dao.list(storage,currentpage); request.setAttribute("Storages",object[0]); request.setAttribute("page", object[1]); //将storage设为request的属性,方便点击“下一页”使用 request.setAttribute("storageForm",storage); return mapping.findForward("list"); } /** * 删除仓库信息 */ public ActionForward delete( ActionMapping mapping, ActionForm form, HttpServletRequest request, HttpServletResponse response)throws Exception{ String id = request.getParameter("id"); if(id!=null&&id.trim().length()>0){ StorageDAO dao = new StorageDAO(); dao.delete(Integer.valueOf(id)); saveMessage(request,"assetStorageForm.deleted"); } return mapping.findForward("success"); } /** * 检索所有仓库信息 */ public ActionForward findAll( ActionMapping mapping, ActionForm form, HttpServletRequest request, HttpServletResponse response)throws Exception{ StorageDAO dao = new StorageDAO(); List<Storage> list = dao.findAll(); request.setAttribute("assetTypes", list); return mapping.findForward("success"); }}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -