mirror of
https://github.com/continew-org/continew-admin.git
synced 2025-10-25 18:57:11 +08:00
refactor: 适配 ContiNew Starter MyBatis Plus 自动配置
This commit is contained in:
@@ -17,24 +17,30 @@
|
||||
<description>公共模块(存放公共工具类,公共配置等)</description>
|
||||
|
||||
<dependencies>
|
||||
<!-- ContiNew Starter API 文档依赖 -->
|
||||
<!-- ContiNew Starter 数据访问模块 - MyBatis Plus -->
|
||||
<dependency>
|
||||
<groupId>top.charles7c.continew</groupId>
|
||||
<artifactId>continew-starter-api-doc</artifactId>
|
||||
<artifactId>continew-starter-data-mybatis-plus</artifactId>
|
||||
</dependency>
|
||||
|
||||
<!-- ContiNew Starter Redisson 依赖(Redis 缓存) -->
|
||||
<!-- ContiNew Starter 缓存模块 - Redisson -->
|
||||
<dependency>
|
||||
<groupId>top.charles7c.continew</groupId>
|
||||
<artifactId>continew-starter-cache-redisson</artifactId>
|
||||
</dependency>
|
||||
|
||||
<!-- ContiNew Starter Jackson 依赖(JSON) -->
|
||||
<!-- ContiNew Starter JSON 模块 - Jackson -->
|
||||
<dependency>
|
||||
<groupId>top.charles7c.continew</groupId>
|
||||
<artifactId>continew-starter-json-jackson</artifactId>
|
||||
</dependency>
|
||||
|
||||
<!-- ContiNew Starter API 文档模块 -->
|
||||
<dependency>
|
||||
<groupId>top.charles7c.continew</groupId>
|
||||
<artifactId>continew-starter-api-doc</artifactId>
|
||||
</dependency>
|
||||
|
||||
<!-- ################ Spring Boot 相关 ################ -->
|
||||
<!-- Java 邮件支持 -->
|
||||
<dependency>
|
||||
@@ -66,31 +72,12 @@
|
||||
<artifactId>sa-token-jwt</artifactId>
|
||||
</dependency>
|
||||
|
||||
<!-- ################ 持久层相关 ################ -->
|
||||
<!-- MyBatis Plus(MyBatis 的增强工具,在 MyBatis 的基础上只做增强不做改变,简化开发、提高效率) -->
|
||||
<dependency>
|
||||
<groupId>com.baomidou</groupId>
|
||||
<artifactId>mybatis-plus-spring-boot3-starter</artifactId>
|
||||
</dependency>
|
||||
|
||||
<!-- Dynamic Datasource(基于 Spring Boot 的快速集成多数据源的启动器) -->
|
||||
<dependency>
|
||||
<groupId>com.baomidou</groupId>
|
||||
<artifactId>dynamic-datasource-spring-boot3-starter</artifactId>
|
||||
</dependency>
|
||||
|
||||
<!-- MySQL Java 驱动 -->
|
||||
<dependency>
|
||||
<groupId>com.mysql</groupId>
|
||||
<artifactId>mysql-connector-j</artifactId>
|
||||
</dependency>
|
||||
|
||||
<!-- P6Spy(SQL 性能分析组件) -->
|
||||
<dependency>
|
||||
<groupId>p6spy</groupId>
|
||||
<artifactId>p6spy</artifactId>
|
||||
</dependency>
|
||||
|
||||
<!-- ################ 工具库相关 ################ -->
|
||||
<!-- SMS4J(短信聚合框架,轻松集成多家短信服务,解决接入多个短信 SDK 的繁琐流程) -->
|
||||
<dependency>
|
||||
|
||||
@@ -38,26 +38,8 @@ import cn.hutool.core.net.NetUtil;
|
||||
* @since 2022/12/22 19:51
|
||||
*/
|
||||
@Configuration
|
||||
@MapperScan("${mybatis-plus.mapper-package}")
|
||||
public class MybatisPlusConfiguration {
|
||||
|
||||
/**
|
||||
* 插件配置
|
||||
*
|
||||
* @return /
|
||||
*/
|
||||
@Bean
|
||||
public MybatisPlusInterceptor mybatisPlusInterceptor() {
|
||||
MybatisPlusInterceptor interceptor = new MybatisPlusInterceptor();
|
||||
// 数据权限插件
|
||||
interceptor.addInnerInterceptor(new DataPermissionInterceptor(new DataPermissionHandlerImpl()));
|
||||
// 分页插件
|
||||
interceptor.addInnerInterceptor(paginationInnerInterceptor());
|
||||
// 防全表更新与删除插件
|
||||
interceptor.addInnerInterceptor(new BlockAttackInnerInterceptor());
|
||||
return interceptor;
|
||||
}
|
||||
|
||||
/**
|
||||
* 元对象处理器配置(插入或修改时自动填充)
|
||||
*/
|
||||
@@ -65,26 +47,4 @@ public class MybatisPlusConfiguration {
|
||||
public MetaObjectHandler metaObjectHandler() {
|
||||
return new MyBatisPlusMetaObjectHandler();
|
||||
}
|
||||
|
||||
/**
|
||||
* ID 生成器配置,仅在主键类型(idType)配置为 ASSIGN_ID 或 ASSIGN_UUID 时有效(使用网卡信息绑定雪花生成器,防止集群雪花 ID 重复)
|
||||
*/
|
||||
@Bean
|
||||
public IdentifierGenerator idGenerator() {
|
||||
return new DefaultIdentifierGenerator(NetUtil.getLocalhost());
|
||||
}
|
||||
|
||||
/**
|
||||
* 分页插件配置(<a href="https://baomidou.com/pages/97710a/#paginationinnerinterceptor">...</a>)
|
||||
*/
|
||||
private PaginationInnerInterceptor paginationInnerInterceptor() {
|
||||
// 对于单一数据库类型来说,都建议配置该值,避免每次分页都去抓取数据库类型
|
||||
// PaginationInnerInterceptor paginationInnerInterceptor = new PaginationInnerInterceptor();
|
||||
PaginationInnerInterceptor paginationInnerInterceptor = new PaginationInnerInterceptor(DbType.MYSQL);
|
||||
// 溢出总页数后是否进行处理,默认不处理
|
||||
paginationInnerInterceptor.setOverflow(false);
|
||||
// 单页分页条数限制,默认无限制
|
||||
paginationInnerInterceptor.setMaxLimit(-1L);
|
||||
return paginationInnerInterceptor;
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user