项目一开始未引入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; } }标签:InsertBatchSomeColumn,sqlSessionFactory,自定义,bound,mybatis,new,public From: https://blog.csdn.net/m0_64923191/article/details/141391108