在使用mybatis进行批量更新时报错:
Cause: java.sql.SQLException: sql injection violation, multi-statement not allow :XXX
找到报错的sql语句:
<update id="moveDevices">
<foreach collection="deviceIds" item="deviceId" index="index" open="" close="" separator=";">
update t_device
<set>
device_group_id = #{groupId}
</set>
<where>
id = #{deviceId}
</where>
</foreach>
</update>
这种将循环语句嵌套在外层的sql语句是因为配置不支持导致的,网上搜这个错误几乎都是修改 配置,大家需要可自行百度。
我这里是批量移动设备,所以是将设备列表修改同一个字段,可以改一种写法而不必进行配置
<update id="moveDevices">
update t_device
<set>
device_group_id = #{groupId}
</set>
<where>
id in
<foreach collection="deviceIds" item="deviceId" open="(" close=")" separator=",">
#{deviceId}
</foreach>
</where>
</update>