zoukankan      html  css  js  c++  java
  • updateprimarykey 和updateprimaryKeySelective

     updateprimarykey 会对左右的字段都进行更新,updateprimaryKeySelective 只会对不为null的字段进行更新。。所以在填表的web项目需要注意这个两个方法的选择,因为有的选项会传null,如果允许传null,那么第二个方方法就没有更新效果。

    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对你注入的字段全部更新
    参考文章:https://blog.csdn.net/a670941001/article/details/54619432

  • 相关阅读:
    蓝桥杯 算法训练 ALGO-118 连续正整数的和
    迭代器和生成器
    字符串格式化
    python 赋值 深浅拷贝
    web.py
    urlib2 标准代码
    left menu
    tab menu
    modal html
    emmet使用
  • 原文地址:https://www.cnblogs.com/prader6/p/12039154.html
Copyright © 2011-2022 走看看