clientdispatchaction.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.ClientDAO;
import com.qrsx.appcam.form.ClientForm;
import com.qrsx.appcam.model.Client;
public class ClientDispatchAction 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");
}
//获取表单中的数据,把该数据复制到client对象中去
ClientForm factoryForm = (ClientForm) form;
Client factory = new Client();
BeanUtils.copyProperties(factory, form);
ClientDAO dao = new ClientDAO();
//判断对象Id是否为空,若为空则执行创建操作,否则执行更新操作
if (factoryForm.getId() == null
|| factoryForm.getId().trim().length() == 0) {
dao.create(factory);
saveMessage(request, "FactoryForm.added", factoryForm.getName());
} else {
dao.update(factory);
saveMessage(request, "FactoryForm.updated", factoryForm.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) {
ClientDAO dao = new ClientDAO();
//获取要编辑的对象信息
Client factory = dao.findById(Integer.valueOf(id));
if (factory != null) {
//把该对象数据,映射到表单中去
BeanUtils.copyProperties(form, factory);
}
}
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) {
ClientDAO dao = new ClientDAO();
dao.delete(Integer.valueOf(id));
saveMessage(request, "deptmentForm.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);
Client factory = new Client();
//把检索条件映射到对象中
BeanUtils.copyProperties(factory, form);
ClientDAO dao = new ClientDAO();
//执行检索操作,并把检索结果返回list页面
List<Client> list = dao.list(factory);
request.setAttribute("factorys", 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);
ClientDAO dao = new ClientDAO();
List<Client> list = dao.findAll();
request.setAttribute("factorys", list);
return mapping.findForward("list");
}
}
⌨️ 快捷键说明
复制代码Ctrl + C
搜索代码Ctrl + F
全屏模式F11
增大字号Ctrl + =
减小字号Ctrl + -
显示快捷键?