zoukankan      html  css  js  c++  java
  • 做update业务时,碰到的问题,serialize

    在controller层,请求参数传入的id,并未在代码中书写使用。而是由springmvc自动封装成了bean对象

    @ResponseBody
        @RequestMapping("/roleUpdate/{id}")
        public String roleUpdate(Role role) {
            
             System.out.println("role  ----------"+role.toString());
        //     System.out.println("request ------------"+request.getParameter("description"));
             roleService.modifyRole(role);
             return null;
        }

    这层的role实体bean,如何而来,需要前台封装bean,举例用jquery的,就是给form表单加入name属性,然后ajax的serialize来传递。

    在dao层,接口层

    public int modifyRole(Role role);

    在mapper的xml文件

    <update id="modifyRole" parameterType="cn.taotao.bean.Role">
    update tbl_role 
    <set>
    <if test="name != null">
    name= #{name,jdbcType=VARCHAR},
    </if>
    <if test="description != null">
    description = #{description,jdbcType=VARCHAR},
    </if>
    </set>
    where id=#{id,jdbcType=INTEGER}
    </update>

    springmvc,自己集成了把一个map对象封装成一个bean的功能,只要提供dao层(where id = ?)和cotroller层的传入实体bean,就可以完成修改功能。

  • 相关阅读:
    BZOJ2870 最长道路
    为什么要设置Java环境变量
    JavaMail收发邮件的步骤
    Java 7开发者预览版发布
    J2EE的13种核心技术
    jdk1.5、1.6、1.7新特性详细介绍(整理)
    JAVAEE5 VS JAVAEE6
    TOCMAT的web.xml详解(转贴)
    setAttribute()和getAttribute()
    jsp servlet的区别和联系
  • 原文地址:https://www.cnblogs.com/sdgtxuyong/p/12055401.html
Copyright © 2011-2022 走看看