📄 00d4a6ccec2d001d141adb233f2e4e02
字号:
/**
*
*/
package com.qrsx.qrsxcrm.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.ActionForm;
import org.apache.struts.action.ActionForward;
import org.apache.struts.action.ActionMapping;
import com.qrsx.qrsxcrm.dao.DeptDAO;
import com.qrsx.qrsxcrm.dao.ProductionDAO;
import com.qrsx.qrsxcrm.form.ProductionForm;
import com.qrsx.qrsxcrm.model.Dept;
import com.qrsx.qrsxcrm.model.Production;
import com.qrsx.qrsxcrm.model.ProductionType;
import com.qrsx.qrsxcrm.web.Pager;
/**
* @author Administrator
*
*/
public class ProductionAction extends BaseDispatchAction
{
@SuppressWarnings("unchecked")
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 edit(mapping,form,request,response);
// }
Dept dept=new Dept();
BeanUtils.copyProperties(dept,form);
DeptDAO deptDao=new DeptDAO(Dept.class);
if( dept.getId()==null||dept.getId().trim().length()==0 ){
deptDao.create(dept);
saveMessage(request,"create" ,dept.getDeptName());
}
else{
deptDao.updates(dept);
saveMessage(request,"update",dept.getDeptName());
}
return mapping.findForward("success");
}
@SuppressWarnings("unchecked")
public ActionForward list(ActionMapping mapping,ActionForm form,HttpServletRequest request,HttpServletResponse response) throws Exception{
ProductionDAO productionDAO=new ProductionDAO(Production.class);
Production production=new Production();
BeanUtils.copyProperties(production,form);
ProductionForm productionForm = (ProductionForm)form;
String productionTypeId = productionForm.getProductionTypeId();
if( productionTypeId != null && !productionTypeId.trim().equals("") )
{
ProductionType productionType = (ProductionType) productionDAO.findById(Production.class, productionTypeId);
production.setProductionType(productionType);
}
@SuppressWarnings("unused")
List<ProductionType> productionTypes = productionDAO.findAll("from ProductionType");
request.setAttribute("productionTypes", productionTypes);
try {
Pager pager = null;
List results = productionDAO.findAll("from Production");//得到总数据
pager = new Pager(); // 构造分页对象
int totalRows = results.size(); // 得到总数据量
pager.init(totalRows);
if (request.getParameter("action") != null) {
pager.doAction(request.getParameter("action").toString());
}
// 使用分页标签的方法
List list = productionDAO.findAllByPage(production, (pager.getCurrentPage() - 1)* pager.getPageSize(),pager.getPageSize());
request.getSession().setAttribute("pagerstruts", pager);
request.setAttribute("productions", list);
} catch (Exception e) {
e.printStackTrace();
}
return mapping.findForward("list");
}
@SuppressWarnings("unchecked")
public ActionForward edit(ActionMapping mapping,ActionForm form,HttpServletRequest request,HttpServletResponse response) throws Exception{
String id=request.getParameter("id");
if(id!=null&&id.trim().length()>0){
ProductionDAO productionDAO=new ProductionDAO(Production.class);
Production production =(Production) productionDAO.findById( Production.class, id);
List<ProductionType> productionTypes = productionDAO.findAll("from ProductionType");
request.setAttribute("productionTypes", productionTypes);
if (production!=null){
BeanUtils.copyProperties(form,production);
}
}
return mapping.findForward("edit");
}
@SuppressWarnings("unchecked")
public ActionForward delete(ActionMapping mapping,ActionForm form,HttpServletRequest request,HttpServletResponse response) throws Exception{
String id=request.getParameter("id");
DeptDAO deptDao=new DeptDAO(Dept.class);
Dept dept =(Dept) deptDao.findById( Dept.class, id);
deptDao.delete(dept);
return mapping.findForward("success");
}
public ActionForward info(ActionMapping mapping,ActionForm form,HttpServletRequest request,HttpServletResponse response) throws Exception{
String id=request.getParameter("id");
if(id!=null&&id.trim().length()>0){
DeptDAO deptDao=new DeptDAO(Dept.class);
Dept dept =(Dept) deptDao.findById( Dept.class, id);
request.setAttribute("dept",dept);
}
return mapping.findForward("info");
}
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -