自己搭一个项目,spring boot+mybatis-plus,引用mybatis-plus 执行发现自己写的sql可以执行,执行basemapper里的方法就会出错,
mybatis-plus Invalid bound statement (not found)
检查文件(application.yml、mapper.xml等)配置,编译加载是否正确
发现都没什么问题,包加载也替换了几个版本,还是不行,
后面发现需要将mybatis的sqlSessionFactory替换成mybatis-plusd的MybatisSqlSessionFactoryBean
因为是自己写的sqlSessionFactory加载一直也没注意到这个问题,使用默认配置应该也没有这个问题,记录下
@Bean("sqlSessionFactory")
@Primary
public SqlSessionFactory sqlSessionFactory(@Autowired @Qualifier("dataSource") DataSource dataSource) throws Exception {
MybatisSqlSessionFactoryBean sqlSessionFactoryBean = new MybatisSqlSessionFactoryBean();
sqlSessionFactoryBean.setDataSource(dataSource);
sqlSessionFactoryBean.setMapperLocations(new PathMatchingResourcePatternResolver().getResources("classpath:mapper/*.xml"));
// Interceptor interceptor = new PageInterceptor();
// Properties properties = new Properties();
// properties.setProperty("helperDialect", "sqlserver");
// properties.setProperty("offsetAsPageNum", "true");
// properties.setProperty("rowBoundsWithCount", "true");
// properties.setProperty("reasonable", "false");
// interceptor.setProperties(properties);
// sqlSessionFactoryBean.setPlugins(new Interceptor[] {interceptor});
return sqlSessionFactoryBean.getObject();
}