首页 > 其他 > 详细

Mybatis中updateByPrimaryKeySelective和updateByPrimaryKey区别

时间:2019-07-07 16:45:49      阅读:91      评论:0      收藏:0      [点我收藏+]

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

 

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

 

上面的是逆转工程生成的Mapper接口

对应的xml为

<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>
<update id="updateByPrimaryKey" parameterType="com.taotao.pojo.TbItem">
update tb_item
set title = #{title,jdbcType=VARCHAR},
where id = #{id,jdbcType=BIGINT}
</update>

  

updateByPrimaryKeySelective会对字段进行判断再更新(如果为Null就忽略更新),如果你只想更新某一字段,可以用这个方法。

updateByPrimaryKey对你注入的字段全部更新

Mybatis中updateByPrimaryKeySelective和updateByPrimaryKey区别

原文:https://www.cnblogs.com/xinruyi/p/11146697.html

(0)
(0)
   
举报
评论 一句话评论(0
关于我们 - 联系我们 - 留言反馈 - 联系我们:wmxa8@hotmail.com
© 2014 bubuko.com 版权所有
打开技术之扣,分享程序人生!