|
|
@ -1,20 +1,31 @@
|
|
|
|
|
|
|
|
// 定义当前类所在的包路径
|
|
|
|
package com.shanzhu.market.common.config;
|
|
|
|
package com.shanzhu.market.common.config;
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
// 导入需要的类库
|
|
|
|
import com.baomidou.mybatisplus.annotation.DbType;
|
|
|
|
import com.baomidou.mybatisplus.annotation.DbType;
|
|
|
|
import com.baomidou.mybatisplus.extension.plugins.MybatisPlusInterceptor;
|
|
|
|
import com.baomidou.mybatisplus.extension.plugins.MybatisPlusInterceptor;
|
|
|
|
import com.baomidou.mybatisplus.extension.plugins.inner.PaginationInnerInterceptor;
|
|
|
|
import com.baomidou.mybatisplus.extension.plugins.inner.PaginationInnerInterceptor;
|
|
|
|
import org.springframework.context.annotation.Bean;
|
|
|
|
import org.springframework.context.annotation.Bean;
|
|
|
|
import org.springframework.context.annotation.Configuration;
|
|
|
|
import org.springframework.context.annotation.Configuration;
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
// 声明这是一个Spring配置类
|
|
|
|
@Configuration
|
|
|
|
@Configuration
|
|
|
|
|
|
|
|
// 定义MyBatis-Plus配置类
|
|
|
|
public class MpConfig {
|
|
|
|
public class MpConfig {
|
|
|
|
|
|
|
|
// 配置MyBatis-Plus分页插件的Bean
|
|
|
|
/*mybatis plus分页插件生效*/
|
|
|
|
/*mybatis plus分页插件生效*/
|
|
|
|
@Bean
|
|
|
|
@Bean
|
|
|
|
|
|
|
|
// 创建MyBatis-Plus拦截器实例
|
|
|
|
public MybatisPlusInterceptor mybatisPlusInterceptor() {
|
|
|
|
public MybatisPlusInterceptor mybatisPlusInterceptor() {
|
|
|
|
|
|
|
|
// 实例化MyBatis-Plus拦截器
|
|
|
|
MybatisPlusInterceptor interceptor = new MybatisPlusInterceptor();
|
|
|
|
MybatisPlusInterceptor interceptor = new MybatisPlusInterceptor();
|
|
|
|
|
|
|
|
// 创建MySQL分页拦截器实例,指定数据库类型为MySQL
|
|
|
|
PaginationInnerInterceptor paginationInnerInterceptor = new PaginationInnerInterceptor(DbType.MYSQL);
|
|
|
|
PaginationInnerInterceptor paginationInnerInterceptor = new PaginationInnerInterceptor(DbType.MYSQL);
|
|
|
|
|
|
|
|
// 设置溢出时自动调整到合理页码(合理化配置)
|
|
|
|
paginationInnerInterceptor.setOverflow(true); //合理化
|
|
|
|
paginationInnerInterceptor.setOverflow(true); //合理化
|
|
|
|
|
|
|
|
// 将分页拦截器添加到拦截器链中
|
|
|
|
interceptor.addInnerInterceptor(paginationInnerInterceptor);
|
|
|
|
interceptor.addInnerInterceptor(paginationInnerInterceptor);
|
|
|
|
|
|
|
|
// 返回配置好的拦截器实例
|
|
|
|
return interceptor;
|
|
|
|
return interceptor;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|