近期在项目中遇到一个需要批量更新的场景,因此想到了使用Mybatis的 foreach 标签来完成,Mapper里的sql如下:
<update id="" parameterType="java.util.List">
<foreach collection="list" item="item" separator=";" >
update xxxx
set enabled = 1
<where>
task_code=#{item.xxx} and apply_tenant_num=#{item.xx}
</where>
</foreach>
</update>
通过插件获取到sql语句,没发现什么问题,但一直报如下错误:
### The error may involve org.srm.adaptor.infra.mapper.xxxxMapper.xxxxx-Inline
### The error occurred while setting parameters
一直查不出错误,后面发现正常情况下Mybatis是不支持一次性插入多条SQL的,如果想要支持这个功能,需要在 database.url中添加**&allowMultiQueries=true**来进行支持,添加这个设置后,问题解决