mybatis-plus配置自定义sqlInjector(使用InsertBatchSomeColumn),出现Invalid bound statement (not found)

项目一开始未引入mybatis-plus,使用的是mybatis,配置文件为xml,有一个配置类中配置了SqlSessionFactory的相关内容。

引入mybatis-plus后,想使用InsertBatchSomeColumn遇到Invalid bound statement (not found),多处配置发现没有效果并依旧报错,最终在刚才的配置类中的SqlSessionFactory代码部分加入以下代码成功解决:

    @Bean(name = "anotherSessionFactory")
    public SqlSessionFactory pstoreSessionFactory(@Qualifier("anotherDataSource") DataSource dataSource) throws Exception {
        MybatisSqlSessionFactoryBean sqlSessionFactory = new MybatisSqlSessionFactoryBean();
        sqlSessionFactory.setDataSource(dataSource);
        sqlSessionFactory.setConfigLocation(new ClassPathResource(myBatisConfigClassPath));  // xml文件中的配置
        sqlSessionFactory.setFailFast(true);

        // 以下为新增代码
        // 添加mybatis-plus自定义SqlInjector
        GlobalConfig globalConfig = new GlobalConfig();
        globalConfig.setSqlInjector(mySqlInjector());
        sqlSessionFactory.setGlobalConfig(globalConfig);
        // 以上为新增代码

        return sqlSessionFactory.getObject();
    }

 附上其他相关代码:

在配置类中注入自定义sqlInjector类

@Bean
public MySqlInjector mySqlInjector() {
    return new MySqlInjector();
}
自定义类使用InsertBatchSomeColumn
public class MySqlInjector extends DefaultSqlInjector {
    @Override
    public List<AbstractMethod> getMethodList(Class<?> mapperClass, TableInfo tableInfo) {
        List<AbstractMethod> methodList = super.getMethodList(mapperClass, tableInfo);
        methodList.add(new InsertBatchSomeColumn());
        return methodList;
    }
}
  • 6
    点赞
  • 8
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值