mybatis 批量更新时 sql injection violation, multi-statement not allow 报错解决方法

新增一个配置文件

MybatisConfig

    import com.alibaba.druid.pool.DruidDataSource;
    import com.alibaba.druid.wall.WallConfig;
    import com.alibaba.druid.wall.WallFilter;
    import org.slf4j.Logger;
    import org.slf4j.LoggerFactory;
    import org.springframework.beans.factory.annotation.Autowired;
    import org.springframework.boot.context.properties.ConfigurationProperties;
    import org.springframework.context.annotation.Bean;
    import javax.sql.DataSource;
    import java.util.ArrayList;
    import java.util.List;
    @Configuration
    public class MybatisConfig {
     
        private  final Logger logger = LoggerFactory.getLogger(MybatisConfig.class);
        @Autowired
        WallFilter wallFilter;
        @Bean
     
        @ConfigurationProperties(prefix = "spring.datasource")
     
        public DataSource dataSource() {
     
            DruidDataSource druidDataSource = new DruidDataSource();
     
            List filterList=new ArrayList<>();
     
            filterList.add(wallFilter());
     
            druidDataSource.setProxyFilters(filterList);
     
            return druidDataSource;
     
        }
     
        @Bean
     
        public WallFilter wallFilter(){
     
            WallFilter wallFilter=new WallFilter();
     
            wallFilter.setConfig(wallConfig());
     
            return wallFilter;
     
        }
     
        @Bean
     
        public WallConfig wallConfig(){
     
            WallConfig config =new WallConfig();
     
            config.setMultiStatementAllow(true);//允许一次执行多条语句
     
            config.setNoneBaseStatementAllow(true);//允许非基本语句的其他语句
     
            return config;
     
        }
     
    }

并且数据库连接加上

&allowMultiQueries=true

url: jdbc:mysql://127.0.0.1:3306/machinedatabase?useSSL=false&zeroDateTimeBehavior=convertToNull&autoReconnect=true&allowMultiQueries=true&characterEncoding=UTF-8&characterSetResults=UTF-8

原文链接:https://blog.csdn.net/sinat_23893027/article/details/101034094

你可能感兴趣的:(springBoot,MyBatis,java)