在使用mybatis的批量更新的时候
<update id="updateBatch" parameterType="java.util.List">
<foreach collection="list" item="item" index="index" open="" close="" separator=";">
update student
<set>
name=${item.name}
</set>
where id = ${item.id}
</foreach>
</update>
本以为这样可以直接更新了,谁知道执行的时候直接报错了,my god
后来查到的原因是Mybatis映射文件中的sql语句默认是不支持以" ; " 结尾的,也就是不支持多条sql语句的执行,所以咋办呢,想用批量更新的话需要
在连接mysql的url上加 &allowMultiQueries=true
这样就可以了
打个比方
即在jdbc:mysql://localhost:3306/test 这个后面设置的参数,一定要注意了