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

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
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值