https://github.com/alibaba/druid/wiki/%E9%85%8D%E7%BD%AE-wallfilter可以对应修改参数。
如需要执行多行语句 , 要设置multiStatementAllow为true
查询某个模块数据时,抛出以下异常:
Caused by: java.sql.SQLException: sql injection violation, comment not allow : select count(*) FROM sys_x a WHERE 1=1 --澶囨敞 AND a.organization_id NOT IN( SELECT b.descendant_id FROM sys_y b WHERE b.path_length!=0) at com.alibaba.druid.wall.WallFilter.checkInternal(WallFilter.java:800) at com.alibaba.druid.wall.WallFilter.connection_prepareStatement(WallFilter.java:251) at com.alibaba.druid.filter.FilterChainImpl.connection_prepareStatement(FilterChainImpl.java:473) at com.alibaba.druid.proxy.jdbc.ConnectionProxyImpl.prepareStatement(ConnectionProxyImpl.java:342) at com.alibaba.druid.pool.DruidPooledConnection.prepareStatement(DruidPooledConnection.java:349) at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method) at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62) at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43) at java.lang.reflect.Method.invoke(Method.java:498) at org.springframework.jdbc.datasource.TransactionAwareDataSourceProxy$TransactionAwareInvocationHandler.invoke(TransactionAwareDataSourceProxy.java:239) at com.sun.proxy.$Proxy23.prepareStatement(Unknown Source) at org.springframework.jdbc.core.PreparedStatementCreatorFactory$PreparedStatementCreatorImpl.createPreparedStatement(PreparedStatementCreatorFactory.java:245) at org.springframework.jdbc.core.JdbcTemplate.execute(JdbcTemplate.java:583) ... 59 more 复制代码
<!--配置 druid 拦截过滤器--> <bean id="wall-filter-config" class="com.alibaba.druid.wall.WallConfig" init-method="init"> <!-- 是否允许语句中存在注释--> <property name="commentAllow" value="true" /> </bean> <bean id="wall-filter" class="com.alibaba.druid.wall.WallFilter"> <property name="config" ref="wall-filter-config" /> </bean> 复制代码
然后在 Druid 数据源配置中,加入 Druid 拦截过滤器:
<!--druid 数据源--> <bean id="druidDataSource" class="com.alibaba.druid.pool.DruidDataSource"> ... <!--配置 Druid 过滤器--> <property name="proxyFilters"> <list> ... <ref bean="wall-filter"/> </list> </property> ... </bean> 复制代码
重启应用,看看问题是不是已经解决啦O(∩_∩)O哈哈~