|
|
|
@ -6,20 +6,38 @@ import org.mybatis.spring.annotation.MapperScan;
|
|
|
|
|
import org.springframework.context.annotation.Bean;
|
|
|
|
|
import org.springframework.context.annotation.Configuration;
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
@Configuration
|
|
|
|
|
@MapperScan("com.zsz.mapper")
|
|
|
|
|
/**
|
|
|
|
|
* MyBatis-Plus 配置类
|
|
|
|
|
* 主要功能:
|
|
|
|
|
* 1. 配置MyBatis-Plus的核心插件
|
|
|
|
|
* 2. 指定Mapper接口扫描路径
|
|
|
|
|
* 3. 初始化分页插件等MyBatis-Plus组件
|
|
|
|
|
*/
|
|
|
|
|
@Configuration // 声明当前类是一个Spring配置类,Spring容器启动时会加载这个类
|
|
|
|
|
@MapperScan("com.zsz.mapper") // 指定MyBatis Mapper接口的扫描路径,自动注册这些接口为Bean
|
|
|
|
|
public class MpConfig {
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* 分页插件
|
|
|
|
|
* 配置MyBatis-Plus分页插件
|
|
|
|
|
* 功能说明:
|
|
|
|
|
* 1. 拦截SQL语句自动添加分页逻辑
|
|
|
|
|
* 2. 支持多种数据库的分页语法
|
|
|
|
|
* 3. 可设置最大分页限制防止内存溢出
|
|
|
|
|
*
|
|
|
|
|
* @return 配置好的分页拦截器实例
|
|
|
|
|
*/
|
|
|
|
|
@Bean
|
|
|
|
|
@Bean // 将返回对象注册为Spring容器管理的Bean
|
|
|
|
|
public PaginationInterceptor paginationInterceptor() {
|
|
|
|
|
// 创建分页拦截器实例
|
|
|
|
|
PaginationInterceptor paginationInterceptor = new PaginationInterceptor();
|
|
|
|
|
// paginationInterceptor.setLimit(你的最大单页限制数量,默认 500 条,小于 0 如 -1 不受限制);
|
|
|
|
|
|
|
|
|
|
// 可配置项(当前被注释的示例配置):
|
|
|
|
|
// 设置单页最大记录数限制(默认500条)
|
|
|
|
|
// paginationInterceptor.setLimit(100);
|
|
|
|
|
|
|
|
|
|
// 设置数据库类型(可选,MyBatis-Plus通常能自动识别)
|
|
|
|
|
// paginationInterceptor.setDbType(DbType.MYSQL);
|
|
|
|
|
|
|
|
|
|
return paginationInterceptor;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
}
|
|
|
|
|