做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,就可以完成修改功能。

原文地址:https://www.cnblogs.com/sdgtxuyong/p/12055401.html