SpringMVC_CRM系统_修改数据5

2017-11-12  本文已影响0人  大鹏_xzlp

数据展示出来了,我们接下来进行修改页面数据

  1. 点击修改,在弹出框中要先把用户信息填充进去,需要一个详情接口,我们先来在dao中添加一个方法
    CustomerDao:
 Customer queryCustomerById(Long id);

CustomerDao.xml:

    <select id="queryCustomerById" parameterType="long" resultType="Customer">
        SELECT * FROM customer WHERE cust_id = #{id}
    </select>

Service中增加对应的方法

    public Customer queryCustomerById(Long id){
        return this.customerDao.queryCustomerById(id);
    }

Controller中实现调用

    @RequestMapping("/customer/edit")
    @ResponseBody
    public Customer queryCustomerList(@RequestParam Long id) {
        return this.customerService.queryCustomerById(id);
    }

根据接口返回的数据填充页面


  1. 点击保存修改,调用修改接口,我们先去定义dao中的update方法
    CustomerDao:
    void updateCustomer(Customer customer);

CustomerDao.xml:

<select id="updateCustomer" parameterType="Customer">

        UPDATE `customer`
        SET
        <if test="cust_name !=null and cust_name != ''">
            `cust_name` = #{cust_name},
        </if>
        <if test="cust_user_id !=null">
            `cust_user_id` = #{cust_user_id},
        </if>
        <if test="cust_create_id !=null">
            `cust_create_id` = #{cust_create_id},
        </if>
        <if test="cust_source !=null and cust_source != ''">
            `cust_source` = #{cust_source},
        </if>
        <if test="cust_industry !=null and cust_industry != ''">
            `cust_industry` = #{cust_industry},
        </if>
        <if test="cust_level !=null and cust_level != ''">
            `cust_level` = #{cust_level},
        </if>
        <if test="cust_linkman !=null and cust_linkman != ''">
            `cust_linkman` = #{cust_linkman},
        </if>
        <if test="cust_phone !=null and cust_phone != ''">
            `cust_phone` = #{cust_phone},
        </if>
        <if test="cust_mobile !=null and cust_mobile != ''">
            `cust_mobile` = #{cust_mobile},
        </if>
        <if test="cust_zipcode !=null and cust_zipcode != ''">
            `cust_zipcode` = #{cust_zipcode},
        </if>
        <if test="cust_address !=null and cust_address != ''">
            `cust_address` = #{cust_address},
        </if>
        `cust_createtime` = NOW()
        WHERE
        (`cust_id` = #{cust_id});
    </select>

在Service定义方法

   public void updateCustomer(Customer customer){
       this.customerDao.updateCustomer(customer);
   }

在Controller中实现接口

    @RequestMapping("/customer/update")
    @ResponseBody
    public String updateCustomer(Customer customer){
        System.out.println("updateCustomer");
        this.customerService.updateCustomer(customer);
        return "OK";
    }

这样页面修改完之后点击修改就OK了,后面还有一个删除,这里就不一步步说了,和修改类似,可以直接参考

总结

本系列到此结束,通过一个简单的小型系统来记录梳理一遍SpringMVC的整个开发流程。

本系列源码存放在github上 源码

上一篇下一篇

猜你喜欢

热点阅读