SSH与SSM学习之SSH实现CRM练习05——客户列表05_CustomerAction

来源:互联网 发布:工商局可以投诉淘宝吗 编辑:程序博客网 时间:2024/06/07 03:45

  • SSH与SSM学习之SSH实现CRM练习05客户列表05_CustomerAction
    • 一说明
    • 二CustomerAction
    • 三Spring中添加配置
    • 四Struts2中添加配置
    • 五源码下载

SSH与SSM学习之SSH实现CRM练习05——客户列表05_CustomerAction

一、说明

创建一个名叫做 CustomerAction 的Action ,提供一个 list 方法,用户获取列表数据。

这个list方法主要做以下事情

  1. 调用Service处理 每页逻辑。返回业务需要的结果,就是上面 2.2的结果

  2. 把返回的对象存入到request域中

  3. 转发到list.jsp页面,显示结果


二、CustomerAction

package com.qwm.ssh_crm.web.action;import com.opensymphony.xwork2.ActionContext;import com.opensymphony.xwork2.ActionSupport;import com.opensymphony.xwork2.ModelDriven;import com.qwm.ssh_crm.domain.Customer;import com.qwm.ssh_crm.service.CustomerService;import com.qwm.ssh_crm.utils.PageBean;import org.apache.commons.lang3.StringUtils;import org.hibernate.criterion.DetachedCriteria;import org.hibernate.criterion.Restrictions;/** * @author:qiwenming * @date:2017/11/5 0005   0:34 * @description: * 用户相关Action */public class CustomerAction extends ActionSupport implements ModelDriven<Customer>{    private Customer customer = new Customer();    private CustomerService cs;    private Integer currentPage;    private Integer pageSize;    public String list() throws Exception{        //1.封装离线查询对象        //2.判断并添加参数        //3.调用Service的查询分页数据(PageBean)        //4.把PageBean方法request域中,转发到客户列表界面        DetachedCriteria dc = DetachedCriteria.forClass(Customer.class);        if(StringUtils.isNotBlank(customer.getCust_name())){            dc.add(Restrictions.like("cust_name","%"+customer.getCust_name()+"%"));        }        PageBean pb = cs.getPageBean(dc,currentPage,pageSize);        ActionContext.getContext().put("pageBean",pb);        return "list";    }    @Override    public Customer getModel() {        return customer;    }    public CustomerService getCs() { return cs; }    public void setCs(CustomerService cs) { this.cs = cs; }    public Integer getCurrentPage() { return currentPage; }    public void setCurrentPage(Integer currentPage) { this.currentPage = currentPage; }    public Integer getPageSize() { return pageSize; }    public void setPageSize(Integer pageSize) { this.pageSize = pageSize; }}

三、Spring中添加配置

在Spring的配置文件中(applicationContext.xml),添加如下配置

    <bean name="customerAction" class="com.qwm.ssh_crm.web.action.CustomerAction" scope="prototype">        <property name="cs" ref="customerService"/>    </bean>

四、Struts2中添加配置

在Struts2的配置文件中(struts.xml),添加如下配置

        <action name="CustomerAction_*" class="customerAction" method="{1}">            <result name="list"  >/jsp/customer/list.jsp</result>        </action>

五、源码下载

https://github.com/wimingxxx/ssh_crm

阅读全文
0 0