feat(config): 支持多数据库类型配置及动态分页方言
This commit is contained in:
@@ -7,6 +7,7 @@ import com.baomidou.mybatisplus.extension.plugins.inner.DataPermissionIntercepto
|
||||
import com.baomidou.mybatisplus.extension.plugins.inner.PaginationInnerInterceptor;
|
||||
import com.youlai.boot.plugin.mybatis.MyDataPermissionHandler;
|
||||
import com.youlai.boot.plugin.mybatis.MyMetaObjectHandler;
|
||||
import org.springframework.beans.factory.annotation.Value;
|
||||
import org.springframework.context.annotation.Bean;
|
||||
import org.springframework.context.annotation.Configuration;
|
||||
import org.springframework.transaction.annotation.EnableTransactionManagement;
|
||||
@@ -21,6 +22,9 @@ import org.springframework.transaction.annotation.EnableTransactionManagement;
|
||||
@EnableTransactionManagement
|
||||
public class MybatisConfig {
|
||||
|
||||
@Value("${app.db-type:mysql}")
|
||||
private String dbType;
|
||||
|
||||
/**
|
||||
* 分页插件和数据权限插件
|
||||
*/
|
||||
@@ -29,8 +33,16 @@ public class MybatisConfig {
|
||||
MybatisPlusInterceptor interceptor = new MybatisPlusInterceptor();
|
||||
// 数据权限
|
||||
interceptor.addInnerInterceptor(new DataPermissionInterceptor(new MyDataPermissionHandler()));
|
||||
//分页插件
|
||||
interceptor.addInnerInterceptor(new PaginationInnerInterceptor(DbType.MYSQL));
|
||||
// 分页插件,根据配置动态选择数据库类型
|
||||
DbType mpDbType = DbType.MYSQL;
|
||||
String type = dbType == null ? "mysql" : dbType.toLowerCase();
|
||||
if ("postgres".equals(type) || "postgresql".equals(type)) {
|
||||
mpDbType = DbType.POSTGRE_SQL;
|
||||
} else if ("dm".equals(type) || "dameng".equals(type)) {
|
||||
// 达梦更接近 Oracle 语法,这里选择 ORACLE 方言以获得较好兼容性
|
||||
mpDbType = DbType.ORACLE;
|
||||
}
|
||||
interceptor.addInnerInterceptor(new PaginationInnerInterceptor(mpDbType));
|
||||
|
||||
return interceptor;
|
||||
}
|
||||
|
||||
@@ -1,13 +1,30 @@
|
||||
server:
|
||||
port: 8989
|
||||
|
||||
# 数据库类型:用于 MyBatis-Plus 分页方言等(仅方言,不负责连接信息)
|
||||
app:
|
||||
db-type: mysql # 可选:mysql | postgres | dm
|
||||
|
||||
spring:
|
||||
datasource:
|
||||
type: com.alibaba.druid.pool.DruidDataSource
|
||||
# === MySQL 数据源(默认启用) ===
|
||||
driver-class-name: com.mysql.cj.jdbc.Driver
|
||||
url: jdbc:mysql://www.youlai.tech:3306/youlai_boot?zeroDateTimeBehavior=convertToNull&useUnicode=true&characterEncoding=UTF-8&serverTimezone=Asia/Shanghai&autoReconnect=true&allowMultiQueries=true
|
||||
username: youlai
|
||||
password: 123456
|
||||
|
||||
# === PostgreSQL 数据源示例(按需启用) ===
|
||||
# driver-class-name: org.postgresql.Driver
|
||||
# url: jdbc:postgresql://127.0.0.1:5432/youlai_boot
|
||||
# username: postgres
|
||||
# password: 123456
|
||||
|
||||
# === 达梦 DM 数据源示例(按需启用,注意按实际驱动与 URL 调整) ===
|
||||
# driver-class-name: dm.jdbc.driver.DmDriver
|
||||
# url: jdbc:dm://127.0.0.1:5236?schema=YOULAI_BOOT
|
||||
# username: SYSDBA
|
||||
# password: 123456
|
||||
data:
|
||||
redis:
|
||||
database: 0
|
||||
@@ -74,6 +91,8 @@ spring:
|
||||
response-format:
|
||||
type: json_object
|
||||
|
||||
|
||||
|
||||
mybatis-plus:
|
||||
mapper-locations: classpath*:/mapper/**/*.xml
|
||||
global-config:
|
||||
|
||||
@@ -4,10 +4,23 @@ server:
|
||||
spring:
|
||||
datasource:
|
||||
type: com.alibaba.druid.pool.DruidDataSource
|
||||
# === MySQL 数据源(默认启用) ===
|
||||
driver-class-name: com.mysql.cj.jdbc.Driver
|
||||
url: jdbc:mysql://www.youlai.tech:3306/youlai_boot?zeroDateTimeBehavior=convertToNull&useUnicode=true&characterEncoding=UTF-8&serverTimezone=Asia/Shanghai&autoReconnect=true&allowMultiQueries=true
|
||||
username: youlai
|
||||
password: 123456
|
||||
|
||||
# === PostgreSQL 数据源示例(按需启用) ===
|
||||
# driver-class-name: org.postgresql.Driver
|
||||
# url: jdbc:postgresql://127.0.0.1:5432/youlai_boot
|
||||
# username: postgres
|
||||
# password: 123456
|
||||
|
||||
# === 达梦 DM 数据源示例(按需启用,注意按实际驱动与 URL 调整) ===
|
||||
# driver-class-name: dm.jdbc.driver.DmDriver
|
||||
# url: jdbc:dm://127.0.0.1:5236?schema=YOULAI_BOOT
|
||||
# username: SYSDBA
|
||||
# password: 123456
|
||||
data:
|
||||
redis:
|
||||
database: 11
|
||||
@@ -173,7 +186,7 @@ springdoc:
|
||||
api-docs:
|
||||
path: /v3/api-docs
|
||||
group-configs:
|
||||
- group: '系统管理'
|
||||
- group: "系统管理"
|
||||
paths-to-match: "/**"
|
||||
packages-to-scan:
|
||||
- com.youlai.boot.auth.controller
|
||||
@@ -243,7 +256,6 @@ wx:
|
||||
app-id: xxxxxx
|
||||
app-secret: xxxxxx
|
||||
|
||||
|
||||
# ==================== AI 命令系统配置 ====================
|
||||
ai:
|
||||
# 是否启用 AI 功能
|
||||
|
||||
Reference in New Issue
Block a user