我的工程是springboot的, mybatis 批量更新mysql数据库, 我的xml如下:
<update id="updateBatch" parameterType="java.util.List"> <foreach collection="list" index="index" item="item" separator=";"> update menu_manage <set> <if test="item.name != null" > `name` = #{item.name,jdbcType=VARCHAR}, </if> <if test="item.path != null" > path = #{item.path,jdbcType=VARCHAR}, </if> <if test="item.createTime != null" > create_time = #{item.createTime,jdbcType=TIMESTAMP}, </if> <if test="item.remark != null" > remark = #{item.remark,jdbcType=VARCHAR}, </if> </set> where id = #{item.id,jdbcType=INTEGER} </foreach> </update>
配置这些发现没生效: @Bean(name = "dataSource") @Primary @ConfigurationProperties(prefix = "spring.datasource") public DataSource dataSource() throws PropertyVetoException { DruidDataSource dataSource = new DruidDataSource(); List<Filter> filters = new ArrayList<>(); filters.add(wallFilter()); dataSource.setProxyFilters(filters); return dataSource; } @Bean public WallFilter wallFilter() { WallFilter wallFilter = new WallFilter(); wallFilter.setConfig(wallConfig()); return wallFilter; } @Bean public WallConfig wallConfig() { WallConfig wallConfig = new WallConfig(); //允许一次执行多条语句 wallConfig.setMultiStatementAllow(true); //允许非基本语句的其他语句 wallConfig.setNoneBaseStatementAllow(true); return wallConfig; }
最后在配置文件里,dburl后面加了&allowMultiQueries=true就可以了,也是醉了哦
spring.datasource.url=jdbc:mysql://dev.pc.db:3306/dev_pc_smp2?useUnicode=true&characterEncoding=utf-8&serverTimezone=CTT&allowMultiQueries=true