今天遇到了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
表示允许批量操作。