实例介绍
【实例简介】
【实例截图】
【核心代码】
package com.web.action;
import java.util.List;
import javax.annotation.Resource;
import org.apache.commons.lang3.StringUtils;
import org.apache.struts2.ServletActionContext;
import org.apache.struts2.convention.annotation.Action;
import org.apache.struts2.convention.annotation.Namespace;
import org.apache.struts2.convention.annotation.ParentPackage;
import org.apache.struts2.convention.annotation.Result;
import org.apache.struts2.convention.annotation.Results;
import org.hibernate.criterion.DetachedCriteria;
import org.hibernate.criterion.Restrictions;
import org.springframework.context.annotation.Scope;
import org.springframework.stereotype.Controller;
import com.bean.BaseDict;
import com.bean.Customer;
import com.opensymphony.xwork2.ActionContext;
import com.opensymphony.xwork2.ActionSupport;
import com.opensymphony.xwork2.ModelDriven;
import com.opensymphony.xwork2.util.ValueStack;
import com.service.CustomerService;
import com.web.commons.Page;
@Controller("customerAction")
@Scope("prototype")
@ParentPackage("struts-default")
@Namespace("/customer")
@Results({ @Result(name = "addUI", type = "dispatcher", location = "/jsp/customer/add.jsp"),
@Result(name = "listCustomer", type = "dispatcher", location = "/jsp/customer/list.jsp"),
@Result(name = "allCustomer", type = "redirectAction", location = "findAllCustomer"),
@Result(name = "editUI", type = "dispatcher", location = "/jsp/customer/edit.jsp"),
@Result(name = "industryCount", type = "dispatcher", location = "/jsp/statistic/indlist.jsp"),
@Result(name = "sourceCount", type = "dispatcher", location = "/jsp/statistic/soulist.jsp")
})
public class CustomerAction extends ActionSupport implements ModelDriven<Customer> {
private List list;
private Integer curNum;
private Page<Customer> page;
private List<BaseDict> customerSources;
private List<BaseDict> customerLevels;
@Resource(name = "customerService")
private CustomerService customerService;
private Customer customer = new Customer();
public void setCustomer(Customer customer) {
this.customer = customer;
}
@Override
public Customer getModel() {
return customer;
}
/**
* 客户行业统计
* @return
*/
@Action("customerIndustryCount")
public String customerIndustryCount() {
list=customerService.customerIndustryCount();
return "industryCount";
}
/**
* 客户来源统计
* @return
*/
@Action("customerSourceCount")
public String customerSourceCount() {
list=customerService.findCustomerSourceCount();
return "sourceCount";
}
/**
* 编辑客户
* @return
*/
@Action("editCustomer")
public String editCustomer() {
customerService.updateCustomer(customer);
return "allCustomer";
}
/**
* 获取编辑页面并且回显数据
*
* @return
*/
@Action("editUICustomer")
public String editUICustomer() {
// 查询获取客户来源
customerSources = customerService.findAllCustomerSource();
// 查询所有客户级别
customerLevels = customerService.findAllCustomerLevel();
//此处自己定义对象是为了避免和customer对象造成混淆,模型中的customer和查出获得到的两个customer不是同一个对象,所以如果直接压栈,将会是空
Customer c=customerService.findByIdCustomer(customer.getCust_id());
//把获取到的对象压入值栈
ActionContext.getContext().getValueStack().push(c);
return "editUI";
}
/**
* 根据客户id删除指定的客户
*
* @return
*/
@Action("removeCustomer")
public String removeCustomer() {
customerService.removeByIdCustomer(customer.getCust_id());
return "allCustomer";
}
/**
* 获取添加页面的方法
*
* @return
*/
@Action("addUICustomer")
public String addUICustomer() {
// 查询获取客户来源
customerSources = customerService.findAllCustomerSource();
// 查询所有客户级别
customerLevels = customerService.findAllCustomerLevel();
return "addUI";
}
/**
* 查询所有客户
*
* @return
*/
@Action("findAllCustomer")
public String findAllCustomer() {
//1.创建离线查询东西
DetachedCriteria dCriteria = DetachedCriteria.forClass(Customer.class);
//2.拼装查询条件
//判断是否提供了客户名称,此处将使用apach提供的判断字符串的工具类commm-lang3.jar isNotBlank()可以去掉空格后判断字符串部位null或者""
if (StringUtils.isNotBlank(customer.getCust_name())) {
//添加条件,模糊查询客户名称
dCriteria.add(Restrictions.like("cust_name","%" customer.getCust_name() "%"));
}
//判断是否提供了客户行业
if (StringUtils.isNotBlank(customer.getCust_industry())) {
//添加条件,模糊查询客户行业
dCriteria.add(Restrictions.like("cust_industry","%" customer.getCust_industry() "%"));
}
//判断是否提供了客户来源
if (customer.getCust_source()!=null && StringUtils.isNotBlank(customer.getCust_source().getDict_id())) {
//精确查询客户来源
dCriteria.add(Restrictions.eq("cust_source",customer.getCust_source()));
}
//判断是否提供了客户级别
if (customer.getCust_level()!=null && StringUtils.isNotBlank(customer.getCust_level().getDict_id())) {
//精确查询客户级别
dCriteria.add(Restrictions.eq("cust_level",customer.getCust_level()));
}
//3.按条件查询客户信息
page = customerService.findAllCustomer(dCriteria, curNum);
//4.查询获取客户来源
customerSources = customerService.findAllCustomerSource();
//5.查询所有客户级别
customerLevels = customerService.findAllCustomerLevel();
return "listCustomer";
}
/**
* 新增客户
*
* @return
*/
@Action("addCustomer")
public String addCustomer() {
customerService.saveCustomer(customer);
return "allCustomer";
}
// 把查询到的信息放在值栈中
public List<BaseDict> getCustomerSources() {
return customerSources;
}
public Page<Customer> getPage() {
return page;
}
public void setPage(Page<Customer> page) {
this.page = page;
}
public void setCustomerSources(List<BaseDict> customerSources) {
this.customerSources = customerSources;
}
public List<BaseDict> getCustomerLevels() {
return customerLevels;
}
public void setCustomerLevels(List<BaseDict> customerLevels) {
this.customerLevels = customerLevels;
}
public Integer getCurNum() {
return curNum;
}
public void setCurNum(Integer curNum) {
this.curNum = curNum;
}
public List getList() {
return list;
}
public void setList(List list) {
this.list = list;
}
}
标签: CRM
网友评论
小贴士
感谢您为本站写下的评论,您的评论对其它用户来说具有重要的参考价值,所以请认真填写。
- 类似“顶”、“沙发”之类没有营养的文字,对勤劳贡献的楼主来说是令人沮丧的反馈信息。
- 相信您也不想看到一排文字/表情墙,所以请不要反馈意义不大的重复字符,也请尽量不要纯表情的回复。
- 提问之前请再仔细看一遍楼主的说明,或许是您遗漏了。
- 请勿到处挖坑绊人、招贴广告。既占空间让人厌烦,又没人会搭理,于人于己都无利。
关于好例子网
本站旨在为广大IT学习爱好者提供一个非营利性互相学习交流分享平台。本站所有资源都可以被免费获取学习研究。本站资源来自网友分享,对搜索内容的合法性不具有预见性、识别性、控制性,仅供学习研究,请务必在下载后24小时内给予删除,不得用于其他任何用途,否则后果自负。基于互联网的特殊性,平台无法对用户传输的作品、信息、内容的权属或合法性、安全性、合规性、真实性、科学性、完整权、有效性等进行实质审查;无论平台是否已进行审查,用户均应自行承担因其传输的作品、信息、内容而可能或已经产生的侵权或权属纠纷等法律责任。本站所有资源不代表本站的观点或立场,基于网友分享,根据中国法律《信息网络传播权保护条例》第二十二与二十三条之规定,若资源存在侵权或相关问题请联系本站客服人员,点此联系我们。关于更多版权及免责申明参见 版权及免责申明


支持(0) 盖楼(回复)
支持(0) 盖楼(回复)
支持(0) 盖楼(回复)