Mybatis中updateByPrimaryKeySelective和updateByPrimaryKey區別

摘自: https://blog.csdn.net/a670941001/article/details/54619432java

 

  • int updateByPrimaryKeySelective(TbItem record);
  • int updateByPrimaryKey(TbItem record);

 

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>
相關文章
相關標籤/搜索