版本
<dependency>
<groupId>com.baomidou</groupId>
<artifactId>mybatis-plus-boot-starter</artifactId>
<version>3.4.1</version>
</dependency>
需要配置MybatisPlusInterceptor
@Bean
public MybatisPlusInterceptor mybatisPlusInterceptor() {
MybatisPlusInterceptor interceptor = new MybatisPlusInterceptor();
// 指定数据库方言为 MYSQL
PaginationInnerInterceptor paginationInnerInterceptor = new PaginationInnerInterceptor(DbType.MYSQL);
interceptor.addInnerInterceptor(paginationInnerInterceptor);
return interceptor;
}
最重要的是要在MybatisSqlSessionFactoryBean中放进去插件!
@Bean
@Primary
SqlSessionFactory sqlSessionFactory1() throws Exception {
MybatisSqlSessionFactoryBean bean = new MybatisSqlSessionFactoryBean();
bean.setDataSource(dbOne);
bean.setMapperLocations(resolveMapperLocations());
Interceptor[] plugins = {mybatisPlusInterceptor};
bean.setPlugins(plugins);
return bean.getObject();
}
参考
https://blog.csdn.net/qq32933432/article/details/105752527