mybatis批量更新

 <update id="batchUpdate" parameterType="java.util.List">
        update user1 user1,
        (
        <foreach collection="list" item="item" index="index" separator=" union all ">
            select
            #{item.id,jdbcType=BIGINT} as id,
            #{item.updateUserId,jdbcType=BIGINT} as user_id,
            #{item.updateUserName,jdbcType=VARCHAR} as user_name,
            #{item.recordVersion,jdbcType=INTEGER} as record_version
        </foreach>
        ) tt
        set
        user.user_id = tt.user_id,
        user.user_name = tt.user_name,
        user.update_date = now(),
        user.record_version = tt.record_version + 1
        where
        user.id = tt.id
        and
        user.record_version = tt.record_version
    </update>

  

posted @ 2021-03-10 15:23  生命树gyh  阅读(47)  评论(0编辑  收藏  举报
© 2020 GitHub, Inc.