这篇文章主要介绍了springboot集成mybatis-plus遇到问题怎么办,具有一定借鉴价值,感兴趣的朋友可以参考下,希望大家阅读完这篇文章之后大有收获,下面让小编带着大家一起了解一下。
创新互联公司主营色尼网站建设的网络公司,主营网站建设方案,成都APP应用开发,色尼h5成都微信小程序搭建,色尼网站营销推广欢迎色尼等地区企业咨询
在使用spring boot集成mybatis-plus的过程中遇到的问题
如图,

首先我放xml的包的是没问题的,而是引入的架包和配置问题,问题配置如下

解决方法:请将mybatis-plus改成mybatis,mybatis,mybtis,重要的说三遍,必要的架包如下
org.mybatis.spring.boot mybatis-spring- boot-starter com.baomidou mybatis-plus 2.1.9 org.mybatis.spring.boot mybatis-spring-boot-autoconfigure 1.3.2
注意第一个是mybatis-spring-boot-start ,不是mybatisplus-spring-boot-start还要在mybatis配置文件里声明MybatisSqlSessionFactoryBean,至此问题解决
@Configuration
public class MybatisPlusConfig {
@Autowired
private DataSource dataSource;
@Autowired
private MybatisProperties properties;
@Autowired
private ResourceLoader resourceLoader = new DefaultResourceLoader();
@Autowired(required = false)
private Interceptor[] interceptors;
@Autowired(required = false)
private DatabaseIdProvider databaseIdProvider;
/**
* mybatis-plus分页插件
*/
@Bean
public PaginationInterceptor paginationInterceptor() {
PaginationInterceptor page = new PaginationInterceptor();
page.setDialectType("MySQL");
return page;
}
/**
* 这里全部使用mybatis-autoconfigure 已经自动加载的资源。不手动指定
* 配置文件和mybatis-boot的配置文件同步
* @return
*/
@Bean
public MybatisSqlSessionFactoryBean mybatisSqlSessionFactoryBean() {
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()));
}
mybatisPlus.setConfiguration(properties.getConfiguration());
if (!ObjectUtils.isEmpty(this.interceptors)) {
mybatisPlus.setPlugins(this.interceptors);
}
MybatisConfiguration mc = new MybatisConfiguration();
mc.setDefaultScriptingLanguage(MybatisXMLLanguageDriver.class);
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;
}
}感谢你能够认真阅读完这篇文章,希望小编分享的“springboot集成mybatis-plus遇到问题怎么办”这篇文章对大家有帮助,同时也希望大家多多支持创新互联,关注创新互联行业资讯频道,更多相关知识等着你来学习!