<update id="update">
update sys_user
<set>
<if test="name != null">
name = #{name},
</if>
<if test="chName != null">
ch_name=#{chName},
</if>
<if test="password != null">
password = #{password},
</if>
<if test="groupId != null">
group_id = #{groupId},
</if>
</set>
where id=#{id}
<if test="name != null">
and not exists(select 1 from(select 1 from sys_user where name=#{name} and id != #{id})a)
</if>
update sys_user
<set>
<if test="name != null">
name = #{name},
</if>
<if test="chName != null">
ch_name=#{chName},
</if>
<if test="password != null">
password = #{password},
</if>
<if test="groupId != null">
group_id = #{groupId},
</if>
</set>
where id=#{id}
<if test="name != null">
and not exists(select 1 from(select 1 from sys_user where name=#{name} and id != #{id})a)
</if>
</update>
这里select 1 from(select 1 from sys_user where name=#{name} and id != #{id})a 意思是说mysql如果查血的内容相同的话会报错,而子类是不会报错的
select 1 from(select 1 from sys_user where name=#{name} and id != #{id})a 就是这个不会检查,这么写为了欺骗msql