refactor: 适配 ContiNew Starter MyBatis Plus 自动配置
This commit is contained in:
parent
ec28705b6f
commit
7306cd9d2f
@ -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;
|
||||
}
|
||||
}
|
||||
|
@ -120,9 +120,6 @@ sa-token:
|
||||
|
||||
--- ### MyBatis Plus 配置
|
||||
mybatis-plus:
|
||||
# Mapper 接口扫描包配置(该配置为自定义配置,非 MP 配置,不支持多包,如有需要可通过注解配置或提升扫描包层级)
|
||||
# 该配置目前的唯一使用场景为:@MapperScan("${mybatis-plus.mapper-package}")
|
||||
mapper-package: ${project.basePackage}.**.mapper
|
||||
# Mapper XML 文件目录配置
|
||||
mapper-locations: classpath*:/mapper/**/*Mapper.xml
|
||||
# 类型别名扫描包配置
|
||||
@ -154,6 +151,17 @@ mybatis-plus:
|
||||
logic-delete-value: 1
|
||||
# 逻辑未删除全局值(默认 0,表示未删除)
|
||||
logic-not-delete-value: 0
|
||||
## 扩展配置
|
||||
extension:
|
||||
enabled: true
|
||||
# Mapper 接口扫描包配置
|
||||
mapper-package: ${project.basePackage}.**.mapper
|
||||
# 数据权限实现
|
||||
data-permission-handler-impl: top.charles7c.cnadmin.common.config.mybatis.DataPermissionHandlerImpl
|
||||
# 分页插件配置
|
||||
pagination:
|
||||
enabled: true
|
||||
db-type: mysql
|
||||
|
||||
--- ### 服务器配置
|
||||
server:
|
||||
|
@ -1,30 +0,0 @@
|
||||
############################################################################
|
||||
# P6Spy 配置(SQL 性能分析组件) #
|
||||
############################################################################
|
||||
modulelist=com.baomidou.mybatisplus.extension.p6spy.MybatisPlusLogFactory,com.p6spy.engine.outage.P6OutageFactory
|
||||
# 自定义日志打印
|
||||
logMessageFormat=com.baomidou.mybatisplus.extension.p6spy.P6SpyLogger
|
||||
#日志输出到控制台
|
||||
appender=com.baomidou.mybatisplus.extension.p6spy.StdoutLogger
|
||||
# 使用日志系统记录 SQL
|
||||
#appender=com.p6spy.engine.spy.appender.Slf4JLogger
|
||||
# 设置 P6Spy Driver 代理
|
||||
deregisterdrivers=true
|
||||
# 取消 JDBC URL 前缀
|
||||
useprefix=true
|
||||
# 配置记录 Log 例外,可去掉的结果集有error,info,batch,debug,statement,commit,rollback,result,resultset.
|
||||
excludecategories=info,debug,result,commit,resultset
|
||||
# 日期格式
|
||||
dateformat=yyyy-MM-dd HH:mm:ss
|
||||
# SQL语句打印时间格式
|
||||
databaseDialectTimestampFormat=yyyy-MM-dd HH:mm:ss
|
||||
# 实际驱动可多个
|
||||
#driverlist=org.h2.Driver
|
||||
# 是否启用慢 SQL 记录
|
||||
outagedetection=true
|
||||
# 慢 SQL 记录标准 2 秒
|
||||
outagedetectioninterval=2
|
||||
# 是否过滤 Log
|
||||
filter=true
|
||||
# 过滤 Log 时所排除的 SQL 关键字,以逗号分隔
|
||||
exclude=SELECT 1
|
30
pom.xml
30
pom.xml
@ -3,6 +3,9 @@
|
||||
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
|
||||
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 https://maven.apache.org/xsd/maven-4.0.0.xsd">
|
||||
<modelVersion>4.0.0</modelVersion>
|
||||
<!--
|
||||
下方 parent 为 ContiNew Starter(Continue New Starter),是一种特殊类型的 Spring Boot Starter,其作用与常规的 Starter 类似,它可以帮助开发人员快速集成常用的第三方库或工具到 Spring 应用程序中。ContiNew Starter 包含了一系列经过优化和配置的依赖包(如 MyBatis-Plus、SaToken),可轻松集成到应用中,从而避免开发人员手动引入依赖的麻烦,为 Spring Boot 项目的灵活快速构建提供支持。
|
||||
-->
|
||||
<parent>
|
||||
<groupId>top.charles7c.continew</groupId>
|
||||
<artifactId>continew-starter</artifactId>
|
||||
@ -30,11 +33,6 @@
|
||||
<revision>2.1.0-SNAPSHOT</revision>
|
||||
<sa-token.version>1.37.0</sa-token.version>
|
||||
|
||||
<!-- ### 持久层相关 ### -->
|
||||
<mybatis-plus.version>3.5.4</mybatis-plus.version>
|
||||
<dynamic-ds.version>4.2.0</dynamic-ds.version>
|
||||
<p6spy.version>3.9.1</p6spy.version>
|
||||
|
||||
<!-- ### 工具库相关 ### -->
|
||||
<sms4j.version>3.0.4</sms4j.version>
|
||||
<justauth.version>1.16.5</justauth.version>
|
||||
@ -71,28 +69,6 @@
|
||||
</exclusions>
|
||||
</dependency>
|
||||
|
||||
<!-- ################ 持久层相关 ################ -->
|
||||
<!-- MyBatis Plus(MyBatis 的增强工具,在 MyBatis 的基础上只做增强不做改变,简化开发、提高效率) -->
|
||||
<dependency>
|
||||
<groupId>com.baomidou</groupId>
|
||||
<artifactId>mybatis-plus-spring-boot3-starter</artifactId>
|
||||
<version>${mybatis-plus.version}</version>
|
||||
</dependency>
|
||||
|
||||
<!-- Dynamic Datasource(基于 Spring Boot 的快速集成多数据源的启动器) -->
|
||||
<dependency>
|
||||
<groupId>com.baomidou</groupId>
|
||||
<artifactId>dynamic-datasource-spring-boot3-starter</artifactId>
|
||||
<version>${dynamic-ds.version}</version>
|
||||
</dependency>
|
||||
|
||||
<!-- P6Spy(SQL 性能分析组件) -->
|
||||
<dependency>
|
||||
<groupId>p6spy</groupId>
|
||||
<artifactId>p6spy</artifactId>
|
||||
<version>${p6spy.version}</version>
|
||||
</dependency>
|
||||
|
||||
<!-- ################ 工具库相关 ################ -->
|
||||
<!-- SMS4J(短信聚合框架,轻松集成多家短信服务,解决接入多个短信 SDK 的繁琐流程) -->
|
||||
<dependency>
|
||||
|
Loading…
Reference in New Issue
Block a user