今天遇到了mybatis批量更新操作,会报错的问题。而且从报错上看不出哪里出了问题。
xml文件中的语句这样写的
<update id="updateBatch" parameterType="java.util.List">
<foreach collection="list" item="item" index="index" separator=";">
update user_info
set user_name= #{item.userName,jdbcType=VARCHAR}
where user_id= #{item.userId,jdbcType=INT}
</foreach>
</update>
语句没有任何问题。最后找到原因,批量更新需要在数据库配置中加上
&allowMultiQueries=true
表示允许批量操作。
MyBatis批量更新配置
本文介绍了在使用MyBatis进行批量更新操作时遇到的问题及解决办法。通过在数据库配置中添加allowMultiQueries=true参数,成功实现了批量更新操作。
2184

被折叠的 条评论
为什么被折叠?



