📄 d0d000d0f12b001d10dcc9e30c9e2239
字号:
package com.qrsx.qrsxcrm.action;
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.ActionErrors;
import org.apache.struts.action.ActionForm;
import org.apache.struts.action.ActionForward;
import org.apache.struts.action.ActionMapping;
import com.qrsx.qrsxcrm.dao.ClientDAO;
import com.qrsx.qrsxcrm.form.ClientForm;
import com.qrsx.qrsxcrm.model.Client;
import com.qrsx.qrsxcrm.web.Pager;
/**
* 客户业务操作类
* @author Administrator
*
*/
public class ClientAction extends BaseDispatchAction {
/**
* 列出符合条件的数据
*
* @param mapping
* @param form
* @param request
* @param response
* @return
* @throws InvocationTargetException
* @throws IllegalAccessException
*/
public ActionForward list(ActionMapping mapping, ActionForm form,
HttpServletRequest request, HttpServletResponse response)
throws IllegalAccessException, InvocationTargetException {
Client client = new Client();
BeanUtils.copyProperties(client, form);
try {
Pager pager = null;
ClientDAO cdao = new ClientDAO(Client.class);
List results = cdao.findAll("from Client");//得到总数据
pager = new Pager(); // 构造分页对象
int totalRows = results.size(); // 得到总数据量
pager.init(totalRows);
if (request.getParameter("action") != null) {
pager.doAction(request.getParameter("action").toString());
}
// 使用分页标签的方法
List list = cdao.findAllByPage(client.getClass(), (pager
.getCurrentPage() - 1)
* pager.getPageSize(),pager.getPageSize());
request.getSession().setAttribute("pagerstruts", pager);
request.setAttribute("clients", list);
} catch (Exception e) {
e.printStackTrace();
}
return mapping.findForward("list");
}
/**
* 编辑客户资料,或者点击添加时转到客户编辑页面
*
* @param mapping
* @param form
* @param request
* @param response
* @return
* @throws IllegalAccessException
* @throws InvocationTargetException
*/
public ActionForward edit(ActionMapping mapping, ActionForm form,
HttpServletRequest request, HttpServletResponse response)
throws IllegalAccessException, InvocationTargetException {
String id = request.getParameter("id");
if (id != null && id.trim().length() > 0) {
ClientDAO cdao = new ClientDAO(Client.class);
Client client = (Client) cdao.findById(Client.class, id);
if (client != null) {
BeanUtils.copyProperties(form, client);
}
}
// 组装客户类型,客户联系人,客户负责人
return mapping.findForward("edit");
}
/**
* 保存客户信息
* @param mapping
* @param form
* @param request
* @param response
* @return
* @throws IllegalAccessException
* @throws InvocationTargetException
*/
public ActionForward save(ActionMapping mapping, ActionForm form,
HttpServletRequest request, HttpServletResponse response)
throws IllegalAccessException, InvocationTargetException {
ActionErrors errors = form.validate(mapping, request);
if (!errors.isEmpty()) {
saveErrors(request, errors);
return edit(mapping, form, request, response);
}
ClientForm clientForm=(ClientForm)form;
Client client=new Client();
BeanUtils.copyProperties(client, form);//将from组装到client对象中
//组装一个客户负责人
//组装一个客户类型
//组装一个行业属性
ClientDAO cdao=new ClientDAO(Client.class);
if(clientForm.getId()==null||clientForm.getId().trim().length()==0){
cdao.create(client);
//saveMessage
}
else{
cdao.update(client);
//saveMessage
}
return mapping.findForward("success");
}
/**
* 删除一条信息
* @param mapping
* @param form
* @param request
* @param response
* @return
*/
public ActionForward delete(ActionMapping mapping, ActionForm form,
HttpServletRequest request, HttpServletResponse response){
String id=request.getParameter("id");
if(id!=null&&id.trim().length()>0){
ClientDAO cdao=new ClientDAO(Client.class);
Client client=(Client) cdao.findById(Client.class, id);
cdao.delete(client);
//saveMessage
}
return mapping.findForward("success");
}
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -