1.要是用mp的BaseMapper的crud接口,必須重寫MybatisPlusConfig配置文件,否則掃描不到對應的map接口,報錯找不到什麼statement(具體錯誤記不得了),主要的配置代碼如下:
//此處好像也必須,否則mp的3.x版本會報錯,需要指定DialectType這個玩意
@Bean
public PaginationInterceptor paginationInterceptor() {
PaginationInterceptor page = new PaginationInterceptor();
page.setDialectType("mysql");
return page;
}
//尤其是這個方法,必須重寫,使用MybatisSqlSessionFactoryBean這個Bean
@Bean
public MybatisSqlSessionFactoryBean mybatisSqlSessionFactoryBean() throws IOException {
MybatisSqlSessionFactoryBean mybatisPlus = new MybatisSqlSessionFactoryBean();
mybatisPlus.setDataSource(dataSource);
mybatisPlus.setVfs(SpringBootVFS.class);
if (StringUtils.hasText(this.properties.getConfigLocation())) {
mybatisPlus.setConfigLocation(this.resourceLoader.getResource(this.properties.getConfigLocation()));
}
if (!ObjectUtils.isEmpty(this.interceptors)) {
mybatisPlus.setPlugins(this.interceptors);
}
MybatisConfiguration mc = new MybatisConfiguration();
mc.setDefaultScriptingLanguage(MybatisXMLLanguageDriver.class);
//數據庫字段設計爲駝峯命名,默認開啓的駝峯轉下劃線會報錯字段找不到
mc.setMapUnderscoreToCamelCase(this.properties.getConfiguration().isMapUnderscoreToCamelCase());
mybatisPlus.setConfiguration(mc);
if (this.databaseIdProvider != null) {
mybatisPlus.setDatabaseIdProvider(this.databaseIdProvider);
}
if (StringUtils.hasLength(this.properties.getTypeAliasesPackage())) {
mybatisPlus.setTypeAliasesPackage(this.properties.getTypeAliasesPackage());
}
if (StringUtils.hasLength(this.properties.getTypeHandlersPackage())) {
mybatisPlus.setTypeHandlersPackage(this.properties.getTypeHandlersPackage());
}
if (!ObjectUtils.isEmpty(this.properties.resolveMapperLocations())) {
mybatisPlus.setMapperLocations(this.properties.resolveMapperLocations());
}
}
return mybatisPlus;
}
2.上圖代碼中的properties爲註解的對應的MybatisPlusProperties註解或者MybatisProperties,如下
@Autowired private MybatisPlusProperties properties;
別小看這裏了,這裏配置註解的properties不對應,這個值永遠爲null(別問我爲什麼知道),具體這裏使用哪一個和你項目的yml配置文件有關,看你那裏定義的是mybatis還是mybatis-plus,否則掃描不到對應的配置,切記。
3.項目中的XML或者其他的mapper沒有掃描到一般都是配置的問題,查看對應yml中的配置路徑,是否把本項目中所需要的包路徑都給配置完整。