SpringMVC_CRM系统_修改数据5

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

  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上 源码

最后编辑于
©著作权归作者所有,转载或内容合作请联系作者
平台声明:文章内容(如有图片或视频亦包括在内)由作者上传并发布,文章内容仅代表作者本人观点,简书系信息发布平台,仅提供信息存储服务。

推荐阅读更多精彩内容

  • Android 自定义View的各种姿势1 Activity的显示之ViewRootImpl详解 Activity...
    passiontim阅读 175,256评论 25 709
  • 1. Java基础部分 基础部分的顺序:基本语法,类相关的语法,内部类的语法,继承相关的语法,异常的语法,线程的语...
    子非鱼_t_阅读 31,906评论 18 399
  • Spring Cloud为开发人员提供了快速构建分布式系统中一些常见模式的工具(例如配置管理,服务发现,断路器,智...
    卡卡罗2017阅读 135,347评论 19 139
  • 昨晚没写日记,就是想看看家长和孩子们在没有我的引领下会不会主动写日记,结果让我很满意,家长和孩子们好像丝毫没受到...
    硕mummy阅读 2,415评论 0 4
  • “五一”劳动节嘛,当然要劳动啊,这三天我做了两件事。一搬家,二追《人民的名义》。《人民的名义》成为了我搬家整理物品...
    行走在孤独星球阅读 2,515评论 0 1