抱歉,您的浏览器无法访问本站
本页面需要浏览器支持(启用)JavaScript
了解详情 >

一切得先从我的操作说起。

在集成mybatis-plus过程中,我将 pagehelper-spring-boot-starter 拆成两个依赖包

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
<!-- 分页插件 -->
<!-- <dependency>-->
<!-- <groupId>com.github.pagehelper</groupId>-->
<!-- <artifactId>pagehelper-spring-boot-starter</artifactId>-->
<!-- <version>1.2.5</version>-->
<!-- </dependency>-->
<dependency>
<groupId>com.github.pagehelper</groupId>
<artifactId>pagehelper</artifactId>
<version>5.1.4</version>
</dependency>
<!-- pagehelper 依赖 -->
<dependency>
<groupId>com.github.jsqlparser</groupId>
<artifactId>jsqlparser</artifactId>
<version>1.0</version>
</dependency>

我的一直报 ClassNotFoundException: org.mybatis.logging.LoggerFactory,我判断肯定是mp和pagehelper冲突了,但是pagehelper已经在工程中广泛的使用了,是不可能注释掉的。找打了一篇合适的博客,照着做解决了。

主要解决方法是,把pagehelper-starter springboot启动器拆成底层的两个依赖。但是这样的话,配置就要重新配过了。

1
2
3
4
5
6
7
8
9
10
11
12
<!-- pagehelper-->
<dependency>
<groupId>com.github.pagehelper</groupId>
<artifactId>pagehelper-spring-boot-starter</artifactId>
<version>1.2.5</version>
<exclusions>
<exclusion>
<groupId>org.mybatis</groupId>
<artifactId>mybatis</artifactId>
</exclusion>
</exclusions>
</dependency>

然后手动添加拦截器,拦截com.github.pagehelper

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
package com.xh.sdk.springcloud.config;

import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;

import com.baomidou.mybatisplus.autoconfigure.ConfigurationCustomizer;
import com.baomidou.mybatisplus.core.MybatisConfiguration;
import com.baomidou.mybatisplus.extension.plugins.PaginationInterceptor;

@Configuration
public class MyBatisPlusConfig {

/*
* 分页插件,自动识别数据库类型
* 多租户,请参考官网【插件扩展】
*/
@Bean
public PaginationInterceptor paginationInterceptor() {
return new PaginationInterceptor();
}


@Bean
ConfigurationCustomizer mybatisConfigurationCustomizer() {
return new ConfigurationCustomizer() {
@Override
public void customize(MybatisConfiguration configuration) {
configuration.addInterceptor(new com.github.pagehelper.PageInterceptor());
}
};
}

}

参考链接

解决mybatis plus 3.x 和pagehelper无法共用、包冲突问题
解决Mybatis-plus和pagehelper依赖冲突

从原理出发,很多问题都很好解决。注意这3个文件的配置,一般都能配好

Application.java

1
@MapperScan("com.ifkal.demo.**.mapper") // 要配置的是mapper interface所在的包

application.yml

1
2
3
mybatis-plus:
type-aliases-package: com.ifkal.demo.**.entity
mapper-locations: classpath:com/ifkal/demo/**/mapper/xml/*.xml

官网文档

代码生成器

代码生成器配置

文档理解

代码生成器的名字叫 AutoGenerator

代码生成器配置分为以下几项

  • GlobalConfig 全局配置
  • DataSourceConfig 数据源配置
  • PackageConfig 包配置
  • InjectionConfig 自定义配置(可以猜是不是模板引擎对应的配置了)
  • TemplateConfig 配置模板
  • StrategyConfig 策略配置

注意的事项

  1. DataSourceConfig 必须配置数据库类型