MyBatis-------批量更新

一、Oracle

        在Oracle数据库中批量更新。需要传递一个List集合,然户进行循环执行SQL语句。

        参考网站:https://www.cnblogs.com/feixian/p/5960111.html

        如果操作成功,返回值为  Integer 类型的 -1

        语法如下:  

<update id="updateList" parameterType="List">
        <foreach item="item" collection="list" index="index" open="begin" close=";end;" separator=";">
            UPDATE T_TABLE SET
            A= #{item.a},
            B= #{item.b},
            C= #{item.c},
            D= sysdate
            where ID = #{item.id}
        </foreach>
    </update>

二、MySQL 

        其实就是拼凑出SQL语句。

UPDATE m_classroom
SET name = 3,
 teacherId = 3
WHERE id = 1;

UPDATE m_classroom
SET name = 3,
 teacherId = 3
WHERE id = 2;

 

posted @ 2022-07-17 12:15  小大宇  阅读(239)  评论(0编辑  收藏  举报