摘自: 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>