使用if test标签,可以选择性地更新非空字段。例如
<if test="title != null "> title = #{title,jdbcType=VARCHAR},</if>
但是在使用if test 进行判断时,应注意POJO类中地属性是基本数据类型,还是包装数据类型。
例如
此处point为包装数据类型Double,进行if test判断时应写成
<if test="point != null "> point = #{point,jdbcType=DOUBLE},</if>
如果判断条件写成point != 0.0,则if test判断失效,若此时update不给point赋值,则会将point置为0.0,造成数据的损毁。应特别注意。