修改了user_table对应的xml—/com/UserTableMapper.xml,增加了if标签判断插入的数据是否为空,不为空再插入,之前想在别的地方判断,获取到所有的数据后再全部插入,否则就不插入,尝试了很久,忽然想到mybatis有if的判断,
- UserTableMapper.xml
<update id="updateUserId">
update user_table
<set>
<if test="name!= null">
name=#{name,jdbcType=VARCHAR},
</if>
<if test="age!= null">
name=#{age,jdbcType=VARCHAR},
</if>
<if test="status != null">
status=#{status},
</if>
<if test="receiveTime != null">
receive_time=#{receiveTime,jdbcType=TIMESTAMP},
</if>
<if test="sendTime != null">
send_time=#{sendTime,jdbcType=TIMESTAMP},
</if>
</set>
where transaction_id=#{transactionId,jdbcType=VARCHAR}
</update>
后面查了一下,还有别的标签也可以用
- if
- choose
- trim(where、set)
- foreach
- bind
感兴趣的可以查一下,等后面用到了我再来更新博客。