Mybatis 中更新方法: updateByPrimaryKeySelective() 和 updateByPrimaryKey() 的区别
生活随笔
收集整理的這篇文章主要介紹了
Mybatis 中更新方法: updateByPrimaryKeySelective() 和 updateByPrimaryKey() 的区别
小編覺得挺不錯(cuò)的,現(xiàn)在分享給大家,幫大家做個(gè)參考.
前些天發(fā)現(xiàn)了一個(gè)巨牛的人工智能學(xué)習(xí)網(wǎng)站,通俗易懂,風(fēng)趣幽默,忍不住分享一下給大家。點(diǎn)擊跳轉(zhuǎn)到教程。?
int updateByPrimaryKeySelective(TbItem record); int updateByPrimaryKey(TbItem record);
上面的是逆轉(zhuǎn)工程生成的Mapper接口
對(duì)應(yīng)的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 會(huì)對(duì)字段進(jìn)行判斷再更新(如果為Null就忽略更新),如果你只想更新某一字段,可以用這個(gè)方法。
updateByPrimaryKey 對(duì)你注入的字段全部更新,將為空的字段在數(shù)據(jù)庫中置為NULL
轉(zhuǎn)自:https://blog.csdn.net/a670941001/article/details/54619432?
總結(jié)
以上是生活随笔為你收集整理的Mybatis 中更新方法: updateByPrimaryKeySelective() 和 updateByPrimaryKey() 的区别的全部內(nèi)容,希望文章能夠幫你解決所遇到的問題。
- 上一篇: QT操作sqlite概念
- 下一篇: QT操作sqlite数据库汇总