mybatis批量更新

记录一下 / 2024-04-19 / 原文

xml写法

<update id="updateBatchById" parameterType="java.util.List">
        <foreach collection="userList" index="index" item="user" separator=";">
        update eb_user
        set now_money = #{user.nowMoney}
        where uid = #{user.uid}
    </foreach>
</update>

Mapper类

void updateBatchById(@Param("userList") List<User> userList);

foreach标签的属性collection值 userList 需要和 Mapper类中方法签名中的 userList对应