蔡香满屋
站在牛顿头上吃苹果

 

  1. int updateByPrimaryKeySelective(TbItem record);
  2.  
    int updateByPrimaryKey(TbItem record);


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

对应的xml为

  1.  
    <update id="updateByPrimaryKeySelective" parameterType="com.taotao.pojo.TbItem">
  2.  
    update tb_item
  3.  
    <set>
  4.  
    <if test="title != null">
  5.  
    title = #{title,jdbcType=VARCHAR},
  6.  
    </if>
  7.  
    </set>
  8.  
    where id = #{id,jdbcType=BIGINT}
  9.  
    </update>
  10.  
    <update id="updateByPrimaryKey" parameterType="com.taotao.pojo.TbItem">
  11.  
    update tb_item
  12.  
    set title = #{title,jdbcType=VARCHAR},
  13.  
    where id = #{id,jdbcType=BIGINT}
  14.  
    </update>

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

updateByPrimaryKey 对你注入的字段全部更新,将为空的字段在数据库中置为NULL

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

posted on 2019-09-03 09:59  蔡香满屋  阅读(3837)  评论(0)    收藏  举报