转载自 http://blog.csdn.net/qq_35932345/article/details/55096548
- <span style="font-family:Microsoft YaHei;font-size:18px;"><span style="white-space:pre"> </span>int updateByPrimaryKeySelective(TbItem record);
- <span style="white-space:pre"> </span>int updateByPrimaryKey(TbItem record);</span>
上面的是逆转工程生成的Mapper接口
对应的xml为
- <span style="font-family:Microsoft YaHei;"><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></span>
区别在于如下两点:
1、updateByPrimaryKeySelective会对字段进行判断再更新(如果为Null就忽略更新),如果你只想更新某一字段,可以用这个方法。
2、updateByPrimaryKey对你注入的字段全部更新