mybatis下oracle,mysql 批量更新 寫法

首先這是oracle數據庫的批量更新方法 參數類型是List

<!-- 批量更新排序 -->
    <update id="updatesSort" parameterType="java.util.List">
         <foreach collection="list" item="item" index="index" open="begin" close=";end;" separator=";">
                update sys_office 
                <set>
                  sort=#{item.sort}
                </set>
                where id = #{item.id}
       </foreach>
    </update>

注意的是 close的寫法是 ;end;
好了mysql的 請在鏈接處加上參數

&allowMultiQueries=true

如:

jdbc:mysql://192.168.120.1:3306/mytest?useUnicode=true&amp;characterEncoding=UTF-8&allowMultiQueries=true

然後xml中

<update id="updatesSort"  parameterType="java.util.List">
          <foreach collection="list" item="item" index="index" open="" close="" separator=";">
                update sys_office 
                <set>
                  sort=#{item.sort}
                </set>
                where id = #{item.id}
         </foreach>

    </update>
發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章