mybatis批量更新(update foreach)是多个语句运行失败
最近做项目时遇到一个很奇葩的现象,项目是 Spring + SpringMVC + Mybatis
<update id="batchUpdate" parameterType="java.util.List">
<foreach collection="list" item="item" index="index">
update kpxt_xtsz_spbm
set sl = #{item.slpledit,jdbcType=VARCHAR}
where del_flag=0 and id= #{item.id,jdbcType=VARCHAR};
</foreach>
</update>
int batchUpdate(List list);
public int updateAllspbm(String slpledit,String data){
int result = 0;
String[] dataS = data.split(",");
List list = new ArrayList();
if(dataS.length>0){
for (int i=0;i<dataS.length;i++){
Map map = new HashMap();
map.put("id",dataS[i]);
map.put("slpledit",slpledit);
list.add(map);
}
}
result = spbmMapper.batchUpdate(list);
return result;
}
运行时报错如下:
check the manual that corresponds to your MySQL server version for the right syntax to use near‘update kpxt_xtsz_spbm set sl =? where id=?’
找了很久发现jdbc.properties的url中少了配置
加上 &allowMultiQueries=true 就可以批量执行语句了
