下文笔者将讲述mybatis 实现批量更新的方法分享,如下所示:

实现思路:
1.在jdbc.url 连接符后面加上 &allowMultiQueries=true
2.***maper.xml中设置update语句
3.修改mapper.java文件中的接口方法

例:
mybatis实现批量更新的代码分享

1.xml文件
<update id="updateWeixinUserBatch" parameterType="list">
<foreach item="item" collection="list" separator=";" >
update tableName
set
field1 = #{item.username},
field2= #{item.position}
update_time = #{item.updateTime},
update_by = #{item.updateBy},
eventId = #{item.eventId}
where userid = #{item.userid}
and del_Flag = 0
</foreach>
</update>

2.mapper.java文件
public int updateUserBatch(List<User> user);

 

​转自:http://www.java265.com/JavaFramework/MyBatis/202204/2864.html​