老师,你好!update方法中批量更新报错
来源:7-4 新增部门、部门层级树、更新部门接口自测

LV洪生
2017-11-17
windows10 + IDAE
org.springframework.jdbc.UncategorizedSQLException:
### Error updating database. Cause: java.sql.SQLException: sql injection violation, multi-statement not allow : UPDATE sys_dept
SET level = ?
WHERE id = ?
;
UPDATE sys_dept
SET level = ?
WHERE id = ?
### SQL: UPDATE sys_dept SET level = ? WHERE id = ? ; UPDATE sys_dept SET level = ? WHERE id = ?
。。。。。。。。。。。。。。。。。。
4回答
-
qq_凛冬将至_9
2018-05-06
$ curl http://localhost:8080/sys/dept/update.json?id=23\&name=%E6%8A%80%E6%9C%AF%E6%94%AF%E6%8C%81%E9%83%A8\&seq=6\&parentId=1\&remark=batchUpdate
{"ret":false,"msg":"System error","data":null}
$ curl http://localhost:8080/sys/dept/update.json?id=23\&name=%E6%8A%80%E6%9C%AF%E6%94%AF%E6%8C%81%E9%83%A8\&seq=6\&parentId=1\&remark=batchUpdate
{"ret":true,"msg":null,"data":null}
针对multiStatementAllow参数,建议显式的配置一下是否更好点呢,下面的配置是可行的:
jdbc.url 后面增加&allowMultiQueries=true
连接池DruidDataSource配置改为
<!--<property name="filters" value="stat,wall" />-->
<property name="proxyFilters">
<list>
<ref bean="stat-filter" />
<ref bean="wall-filter"/>
</list>
</property><bean id="wall-filter" class="com.alibaba.druid.wall.WallFilter">
<property name="dbType" value="mysql" />
<property name="config" ref="wall-config" />
</bean>
<bean id="wall-config" class="com.alibaba.druid.wall.WallConfig">
<property name="multiStatementAllow" value="true" />
</bean>
00 -
qq_凛冬将至_9
2018-05-06
SqlMapper里面没错的情况,还是批量更新报错呢
Caused by: java.sql.SQLException: sql injection violation, multi-statement not allow : update sys_dept
set level = ?
WHERE id = ?
;
update sys_dept
set level = ?
WHERE id = ?
;
update sys_dept
set level = ?
WHERE id = ?
;
00 -
loubobooo
2017-11-20
xml里写错了,循环里有一点错误,不要跟着老师的写
00 -
Jimin
2017-11-17
你好,SysDeptMapper.xml 有个sql需要调整一下:
<update id="batchUpdateLevel" parameterType="map">
<foreach collection="sysDeptList" item="sysDept" separator=";">
UPDATE sys_dept
SET level = #{sysDept.level}
WHERE id = #{sysDept.id}
</foreach>
</update>之前这里foreach里的变量给的是sysDept,调用时写的是dept
00
相似问题