mybatisPlus 自定义sqlSessionFactory sql注入器失效 Invalid bound statement (not found): insertBatchSomeColumn

这是重写后的sqlsessionFactory

 @Bean("sqlSessionFactory")
    public SqlSessionFactory sqlSessionFactory() throws Exception {
   
        MybatisSqlSessionFactoryBean sqlSessionFactory = new MybatisSqlSessionFactoryBean();
        sqlSessionFactory.setDataSource(multipleDataSource(db1(),db2()));
        sqlSessionFactory.setMapperLocations(new PathMatchingResourcePatternResolver()
                .getResources("classpath:/com/yaogor/multipledatasource/mapper/*.xml"));
        //添加事物配置(重点)
        sqlSessionFactory.setTransactionFactory(new MultiDataSourceTransactionFactory());
        MybatisConfiguration configuration = new MybatisConfiguration();
        configuration.setDefaultScriptingLanguage(MybatisXMLLanguageDriver.class);
        configuration.setJdbcTypeForNull(JdbcType.NULL);
        configuration.setMapUnderscoreToCamelCase(true);
        configuration.setCacheEnabled(false);
        sqlSessionFactory.setConfiguration(configuration);
        sqlSessionFactory.setPlugins(new Interceptor[]{
    //PerformanceInterceptor(),OptimisticLockerInterceptor()
                paginationInterceptor(), //添加分页功能
        });
        return sqlSessionFactory.getObject();
    }

这是mybatisPlusAutoConfiguration 的sqlsessionfactory

 @ConditionalOnMissingBean
    public SqlSessionFactory sqlSessionFactory(DataSource dataSource) throws Exception {
   
  • 4
    点赞
  • 8
    收藏
    觉得还不错? 一键收藏
  • 3
    评论
根据提供的引用内容,可以看出这个问题涉及到MybatisPlus多数据源和批量插入操作。出现"invalid bound statement (not found)"的错误提示,通常是因为MybatisPlus无法找到对应的Mapper映射文件或者方法名不正确。解决方法如下: 1.检查Mapper映射文件是否存在,以及文件名和路径是否正确。 2.检查Mapper接口中的方法名是否正确,是否与Mapper映射文件中的id一致。 3.检查Mapper接口中的方法参数是否正确,是否与Mapper映射文件中的parameterType一致。 4.检查Mapper接口中的方法返回值是否正确,是否与Mapper映射文件中的resultType一致。 5.检查Mapper接口是否被正确注入到Spring容中。 6.检查数据源配置是否正确,是否与Mapper接口中的@MapperScan注解或者Mapper映射文件中的namespace一致。 以下是一个MybatisPlus多数据源批量插入的示例代码,供参考: ```java // 定义数据源1 DataSource ds1 = DataSourceBuilder.create() .driverClassName("com.mysql.jdbc.Driver") .url("jdbc:mysql://localhost:3306/db1") .username("root") .password("root") .build(); // 定义数据源2 DataSource ds2 = DataSourceBuilder.create() .driverClassName("com.mysql.jdbc.Driver") .url("jdbc:mysql://localhost:3306/db2") .username("root") .password("root") .build(); // 定义MybatisPlusSqlSessionFactory MybatisSqlSessionFactoryBean factoryBean = new MybatisSqlSessionFactoryBean(); factoryBean.setDataSource(dynamicDataSource); factoryBean.setMapperLocations(new PathMatchingResourcePatternResolver().getResources("classpath*:mapper/*.xml")); factoryBean.setTypeAliasesPackage("com.example.demo.entity"); factoryBean.setPlugins(new Interceptor[]{new PaginationInterceptor()}); SqlSessionFactory sqlSessionFactory = factoryBean.getObject(); // 定义MybatisPlusSqlSessionTemplate SqlSessionTemplate sqlSessionTemplate = new SqlSessionTemplate(sqlSessionFactory); // 定义MybatisPlus的Mapper BatchMapper batchMapper = sqlSessionTemplate.getMapper(BatchMapper.class); // 定义批量插入的数据 List<User> userList = new ArrayList<>(); userList.add(new User("张三", 18)); userList.add(new User("李四", 20)); userList.add(new User("王五", 22)); // 执行批量插入操作 batchMapper.batchInsert(userList); ```

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论 3
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值