mybatis 替换为mybatis-plus 调用BaseMapper出现Invalid bound statement (not found)错误

mybatis-plus 可以直接通过yml文件中mybatis-plus.mapper-locations设置mapper文件地址
mybatis-plus:
  mapper-locations: classpath*:com/example/mybatisplus/demo/mapper/xml/*.xml
如果在config类中配置则需要注意mybatis-plus与mybatis的不同
mybatis 使用SqlSessionFactory 而mybatis-plus使用MybatisSqlSessionFactoryBean

所以将SqlSessionFactory

 @Bean
 public SqlSessionFactory masterSessionFactory(@Qualifier("masterDataSource") DataSource dataSource) throws Exception{
     SqlSessionFactoryBean factory = new SqlSessionFactoryBean();
     factory.setDataSource(dataSource);
     factory.setMapperLocations(new PathMatchingResourcePatternResolver().getResources(this.locations));;
     return factory.getObject();
 }

修改为

    @Bean
    MybatisSqlSessionFactoryBean masterSessionFactory(@Qualifier("masterDataSource") DataSource dataSource) throws Exception {
        MybatisSqlSessionFactoryBean mybatisPlus = new MybatisSqlSessionFactoryBean();
        mybatisPlus.setDataSource(dataSource);
        mybatisPlus.setMapperLocations(locations);
        return mybatisPlus;
    }

出现该错误的原因 是在使用mybatis-plus时, 配置文件中使用SqlSessionFactory 进行配置,最后实际是mybatis配置成功,而mybatis-plus未配置,所以出现Invalid bound statement (not found)

参考博客:https://blog.csdn.net/FansUnion/article/details/89081470

你可能感兴趣的:(填坑)