排查问题:
从字面上的问题来看 是mapper接口的查询方法没有绑定,
mybatis-plus中BaseMapper已经帮我们封装好了一系列的单表增删改查,我们无需写配置,就可以实现单表增删改查。但是为什么会出现这种报错呢?
1.我想到了是不是与mybatis的包冲突了,发现并不是,(排除)
2.是不是引入的BaseMapper不同,我引入的是(如图,没问题)
打断点排查,发现问题了
若以的自动配置有这么一段代码我将它注释掉了,
从MybatisPlusAutoConfiguration的源码中,我们可以得知,当项目已经有配置SqlSessionFactory。mybatis-plus将不会自动帮我们注入SqlSessionFactory,而使用我们自己定义的SqlSessionFactory。而若依项目配置的SqlSessionFactory不是MybatisSqlSessionFactoryBean。
所以将我注释掉的代码替换成下面代码:
@Bean
public SqlSessionFactory sqlSessionFactory(DataSource dataSource) throws Exception
{
String typeAliasesPackage = env.getProperty("mybatis.typeAliasesPackage");
String mapperLocations = env.getProperty("mybatis.mapperLocations");
String configLocation = env.getProperty("mybatis.configLocation");
typeAliasesPackage = setTypeAliasesPackage(typeAliasesPackage);
VFS.addImplClass(SpringBootVFS.class);
final MybatisSqlSessionFactoryBean sessionFactory = new MybatisSqlSessionFactoryBean();
sessionFactory.setDataSource(dataSource);
sessionFactory.setTypeAliasesPackage(typeAliasesPackage);
sessionFactory.setMapperLocations(resolveMapperLocations(StringUtils.split(mapperLocations, ",")));
sessionFactory.setConfigLocation(new DefaultResourceLoader().getResource(configLocation));
return sessionFactory.getObject();
}
最后运行plus自带的方法,试了一下,成功了!!!