摘自: https://blog.csdn.net/a670941001/article/details/54619432java
updateByPrimaryKeySelective會對字段進行判斷再更新(若是爲Null就忽略更新),若是你只想更新某一字段,能夠用這個方法。app
updateByPrimaryKeySelective是逆轉工程生成的Mapper接口spa
對應的xml爲.net
<update id="updateByPrimaryKeySelective" parameterType="com.taotao.pojo.TbItem"> update tb_item <set> <if test="title != null"> title = #{title,jdbcType=VARCHAR}, </if> </set> where id = #{id,jdbcType=BIGINT} </update>
updateByPrimaryKey對你注入的字段所有更新 xml
<update id="updateByPrimaryKey" parameterType="com.taotao.pojo.TbItem"> update tb_item set title = #{title,jdbcType=VARCHAR}, where id = #{id,jdbcType=BIGINT} </update>