情况1:没有重新创建SqlSessionFactory的Bean
解决:在配置文件中增加mybatis-puls的mapper扫描路径即可
# MyBatis Plus 的配置项 mybatis-plus: configuration: map-underscore-to-camel-case: true # 虽然默认为 true ,但是还是显示去指定下。 mapper-locations: classpath*:mapper/**/*Mapper.xml
情况2: 如果自己在Config配置类(例如MybatisConfig.java)中重新创建了Bean(SqlSessionFactory)
解决: 将SqlSessionFactoryBean替换为: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 sessionFactory2 = new MybatisSqlSessionFactoryBean(); sessionFactory2.setDataSource(dataSource); sessionFactory2.setTypeAliasesPackage(typeAliasesPackage); sessionFactory2.setMapperLocations(resolveMapperLocations(StringUtils.split(mapperLocations, ","))); sessionFactory2.setConfigLocation(new DefaultResourceLoader().getResource(configLocation)); return sessionFactory2.getObject(); /*final SqlSessionFactoryBean sessionFactory = new SqlSessionFactoryBean(); sessionFactory.setDataSource(dataSource); sessionFactory.setTypeAliasesPackage(typeAliasesPackage); sessionFactory.setMapperLocations(resolveMapperLocations(StringUtils.split(mapperLocations, ","))); sessionFactory.setConfigLocation(new DefaultResourceLoader().getResource(configLocation)); return sessionFactory.getObject();*/ }