SSM框架下,mapper.xml中更新表中不同字段,set写法

以更改用户信息为例,当更改单个用户的不同信息时,xml中代码应该这样写:

<!-- 修改用户信息 -->
<update id="fix" parameterType="user">
update sys_user
<set>
<if test="userName!=null and userName!=''">
userName=#{userName},
</if>
<if test="userPassword!=null and userPassword!=''">
userPassword=#{userPassword},
</if>
<if test="roleId!=null and roleId!=''">
roleId=#{roleId},
</if>
<if test="departId!=null and departId!=''">
departId=#{departId},
</if>
<if test="superiorId!=null and superiorId!=''">
superiorId=#{superiorId},
</if>
</set>
where id=#{id}
</update>

posted on 2017-06-09 11:06  三石为磊  阅读(597)  评论(0编辑  收藏  举报

导航