mybatis批量更新的两种实现方式
生活随笔
收集整理的這篇文章主要介紹了
mybatis批量更新的两种实现方式
小編覺得挺不錯的,現在分享給大家,幫大家做個參考.
mapper.xml文件,后臺傳入一個對象集合,另外如果是mysql數據庫,一點在配置文件上加上&allowMultiQueries=true,這樣才可以執行多條sql,以下為mysql:
<update id="batchUpdate" parameterType="java.util.List"> <foreach separator=";" index="index" item="item" collection="list" close="" open=""> update sys_group set level = #{item.level,jdbcType=INTEGER}where group_id = #{item.groupId,jdbcType=INTEGER}</foreach> </update>
?
如果是oracle數據庫則寫法有不同:
<update id="batchUpdateRepayPlan" parameterType="java.util.List">begin <foreach separator=";" index="index" item="item" collection="list" close="" open=""> update t_ba_repay_plan <set><if test="item.interest !=null">REPAY_INTEREST = #{item.interest,jdbcType=VARCHAR},</if><if test="item.nimm !=null">REPAY_NIMM = #{item.nimm,jdbcType=CHAR}</if></set> where IOU_CODE = #{item.iouCode} </foreach> ;end; </update>
?本文轉自:https://blog.csdn.net/pangliang_csdn/article/details/68945750
轉載于:https://www.cnblogs.com/nizuimeiabc1/p/9559130.html
總結
以上是生活随笔為你收集整理的mybatis批量更新的两种实现方式的全部內容,希望文章能夠幫你解決所遇到的問題。
- 上一篇: “黄梅雨里一人行”上一句是什么
- 下一篇: 求一个恋人微信情侣网名