mybatis批量更新update

猪小花1号2018-11-25 11:40

此文已由作者赵计刚薪授权网易云社区发布。

欢迎访问网易云社区,了解更多网易技术产品运营经验。


一、所有的指定id的模型类的同一个字段进行批量更新

实际上:

update t set fileld='xx' where id in (id1,id2,...,idn)

代码:

<update id="updateBatch" parameterType="Map">
        update t_name
        set name = #{name,jdbcType=VARCHAR}
        where autoid in 
        (
        <foreach collection="list" item="item" separator=",">
            #{item.id,jdbcType=BIGINT}
        </foreach>
        )
    </update>
void updateBatch(@Param("list") List<User> list, @Param("name") String name);

二、指定id的模型类的不同字段进行批量更新

参考:http://blog.csdn.net/tolcf/article/details/39213217


免费体验云安全(易盾)内容安全、验证码等服务

更多网易技术、产品、运营经验分享请点击