📄 deptaction.java
字号:
package com.crm.dept;
import java.io.IOException;
import java.io.PrintWriter;
import java.lang.reflect.InvocationTargetException;
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.ActionForm;
import org.apache.struts.action.ActionForward;
import org.apache.struts.action.ActionMapping;
import org.springframework.context.ApplicationContext;
import org.springframework.web.struts.DispatchActionSupport;
import com.crm.custinfo.CustInfoForm;
import com.crm.custinfo.ICustInfoDAO;
import com.crm.custinfo.po.CustInfo;
import com.crm.dept.po.Dept;
public class DeptAction extends DispatchActionSupport {
public ActionForward list(ActionMapping mapping, ActionForm form,
HttpServletRequest request, HttpServletResponse response) {
DeptForm deptForm = (DeptForm) form;// TODO Auto-generated method stub
ApplicationContext context= this.getWebApplicationContext();
IDeptDAO dao = (IDeptDAO)context.getBean("deptdao");
Dept dept = new Dept();
try {
BeanUtils.copyProperties(dept,deptForm);
} catch (IllegalAccessException e) {
e.printStackTrace();
} catch (InvocationTargetException e) {
e.printStackTrace();
}
List list = dao.getDeptList(dept,request);
request.setAttribute("deptlist", list);
return mapping.findForward("deptlist");
}
public ActionForward insert(ActionMapping mapping, ActionForm form,
HttpServletRequest request, HttpServletResponse response) {
DeptForm deptForm = (DeptForm) form;// TODO Auto-generated method stub
ApplicationContext context= this.getWebApplicationContext();
IDeptDAO dao = (IDeptDAO)context.getBean("deptdao");
Dept dept = new Dept();
System.out.println("deptForm.getFdept_id()="+deptForm.getFdept_id());
try {
BeanUtils.copyProperties(dept,deptForm);
} catch (IllegalAccessException e) {
e.printStackTrace();
} catch (InvocationTargetException e) {
e.printStackTrace();
}
dao.addDept(dept);
try {
PrintWriter out = response.getWriter();
out.println("<script language='javascript'>alert('部门增加成功!');location.href='"+request.getContextPath()+"/manage/deptmanage.do?task=list';</script>");
} catch (IOException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
return null;
}
public ActionForward update(ActionMapping mapping, ActionForm form,
HttpServletRequest request, HttpServletResponse response) {
DeptForm deptForm = (DeptForm) form;// TODO Auto-generated method stub
ApplicationContext context= this.getWebApplicationContext();
IDeptDAO dao = (IDeptDAO)context.getBean("deptdao");
Dept dept = new Dept();
try {
BeanUtils.copyProperties(dept,deptForm);
} catch (IllegalAccessException e) {
e.printStackTrace();
} catch (InvocationTargetException e) {
e.printStackTrace();
}
dao.updateDept(dept);
try {
PrintWriter out = response.getWriter();
out.println("<script language='javascript'>alert('部门修改成功!');location.href='"+request.getContextPath()+"/manage/deptmanage.do?task=list';</script>");
} catch (IOException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
return null;
}
public ActionForward initUpdate(ActionMapping mapping, ActionForm form,
HttpServletRequest request, HttpServletResponse response) {
DeptForm deptForm = (DeptForm) form;// TODO Auto-generated method stub
ApplicationContext context= this.getWebApplicationContext();
IDeptDAO dao = (IDeptDAO)context.getBean("deptdao");
Dept dept = new Dept();
try {
BeanUtils.copyProperties(dept,deptForm);
} catch (IllegalAccessException e) {
e.printStackTrace();
} catch (InvocationTargetException e) {
e.printStackTrace();
}
Dept deptDetail = dao.getDeptDetail(deptForm.getDept_id());
List fdeptlist = dao.getDeptList();
request.setAttribute("fdeptlist", fdeptlist);
try {
BeanUtils.copyProperties(deptForm,deptDetail);
} catch (IllegalAccessException e) {
e.printStackTrace();
} catch (InvocationTargetException e) {
e.printStackTrace();
}
return mapping.findForward("deptdetail");
}
public ActionForward initInsert(ActionMapping mapping, ActionForm form,
HttpServletRequest request, HttpServletResponse response) {
DeptForm deptForm = (DeptForm) form;// TODO Auto-generated method stub
ApplicationContext context= this.getWebApplicationContext();
IDeptDAO dao = (IDeptDAO)context.getBean("deptdao");
List fdeptlist = dao.getDeptList();
request.setAttribute("fdeptlist", fdeptlist);
return mapping.findForward("deptadd");
}
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -