mybatis執行批量更新batch update 的方法(提供oracle,mysql兩種寫法)

oracle和mysql數據庫的批量update在mybatis中配置不太一樣: 

oracle數據庫: 

<update id="updatebatch"  parameterType="java.util.List">

  <foreach collection="list" item="item" index="index" open="begin" close="end;" separator=";">

update table_name 

    <set >

      <if test="item.status != null" >

        status = #{item.status,jdbcType=INTEGER},

      </if>

    </set>

    where id = #{item.id,jdbcType=BIGINT}

  </foreach>

    </update>

mysql數據庫: 

mysql數據庫採用一下寫法即可執行,但是數據庫連接必須配置:&allowMultiQueries=true 

例如:jdbc:mysql://192.168.1.232:3306/test?useUnicode=true&amp;characterEncoding=UTF-8&allowMultiQueries=true 

<update id="updatebatch"  parameterType="java.util.List">

  <foreach collection="list" item="item" index="index" open="" close="" separator=";">

update table_name 

    <set >

      <if test="item.status != null" >

        status = #{item.status,jdbcType=INTEGER},

      </if>

    </set>

    where id = #{item.id,jdbcType=BIGINT}

  </foreach>

       </update>



發佈了58 篇原創文章 · 獲贊 106 · 訪問量 19萬+
發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章