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.baomidou.mybatisplus.extension.plugins.inner.PaginationInnerInterceptor;
|
||||||
import com.youlai.boot.plugin.mybatis.MyDataPermissionHandler;
|
import com.youlai.boot.plugin.mybatis.MyDataPermissionHandler;
|
||||||
import com.youlai.boot.plugin.mybatis.MyMetaObjectHandler;
|
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.Bean;
|
||||||
import org.springframework.context.annotation.Configuration;
|
import org.springframework.context.annotation.Configuration;
|
||||||
import org.springframework.transaction.annotation.EnableTransactionManagement;
|
import org.springframework.transaction.annotation.EnableTransactionManagement;
|
||||||
@@ -21,16 +22,27 @@ import org.springframework.transaction.annotation.EnableTransactionManagement;
|
|||||||
@EnableTransactionManagement
|
@EnableTransactionManagement
|
||||||
public class MybatisConfig {
|
public class MybatisConfig {
|
||||||
|
|
||||||
|
@Value("${app.db-type:mysql}")
|
||||||
|
private String dbType;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 分页插件和数据权限插件
|
* 分页插件和数据权限插件
|
||||||
*/
|
*/
|
||||||
@Bean
|
@Bean
|
||||||
public MybatisPlusInterceptor mybatisPlusInterceptor() {
|
public MybatisPlusInterceptor mybatisPlusInterceptor() {
|
||||||
MybatisPlusInterceptor interceptor = new MybatisPlusInterceptor();
|
MybatisPlusInterceptor interceptor = new MybatisPlusInterceptor();
|
||||||
//数据权限
|
// 数据权限
|
||||||
interceptor.addInnerInterceptor(new DataPermissionInterceptor(new MyDataPermissionHandler()));
|
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;
|
return interceptor;
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1,13 +1,30 @@
|
|||||||
server:
|
server:
|
||||||
port: 8989
|
port: 8989
|
||||||
|
|
||||||
|
# 数据库类型:用于 MyBatis-Plus 分页方言等(仅方言,不负责连接信息)
|
||||||
|
app:
|
||||||
|
db-type: mysql # 可选:mysql | postgres | dm
|
||||||
|
|
||||||
spring:
|
spring:
|
||||||
datasource:
|
datasource:
|
||||||
type: com.alibaba.druid.pool.DruidDataSource
|
type: com.alibaba.druid.pool.DruidDataSource
|
||||||
|
# === MySQL 数据源(默认启用) ===
|
||||||
driver-class-name: com.mysql.cj.jdbc.Driver
|
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
|
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
|
username: youlai
|
||||||
password: 123456
|
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:
|
data:
|
||||||
redis:
|
redis:
|
||||||
database: 0
|
database: 0
|
||||||
@@ -74,6 +91,8 @@ spring:
|
|||||||
response-format:
|
response-format:
|
||||||
type: json_object
|
type: json_object
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
mybatis-plus:
|
mybatis-plus:
|
||||||
mapper-locations: classpath*:/mapper/**/*.xml
|
mapper-locations: classpath*:/mapper/**/*.xml
|
||||||
global-config:
|
global-config:
|
||||||
|
|||||||
@@ -4,10 +4,23 @@ server:
|
|||||||
spring:
|
spring:
|
||||||
datasource:
|
datasource:
|
||||||
type: com.alibaba.druid.pool.DruidDataSource
|
type: com.alibaba.druid.pool.DruidDataSource
|
||||||
|
# === MySQL 数据源(默认启用) ===
|
||||||
driver-class-name: com.mysql.cj.jdbc.Driver
|
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
|
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
|
username: youlai
|
||||||
password: 123456
|
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:
|
data:
|
||||||
redis:
|
redis:
|
||||||
database: 11
|
database: 11
|
||||||
@@ -173,7 +186,7 @@ springdoc:
|
|||||||
api-docs:
|
api-docs:
|
||||||
path: /v3/api-docs
|
path: /v3/api-docs
|
||||||
group-configs:
|
group-configs:
|
||||||
- group: '系统管理'
|
- group: "系统管理"
|
||||||
paths-to-match: "/**"
|
paths-to-match: "/**"
|
||||||
packages-to-scan:
|
packages-to-scan:
|
||||||
- com.youlai.boot.auth.controller
|
- com.youlai.boot.auth.controller
|
||||||
@@ -243,7 +256,6 @@ wx:
|
|||||||
app-id: xxxxxx
|
app-id: xxxxxx
|
||||||
app-secret: xxxxxx
|
app-secret: xxxxxx
|
||||||
|
|
||||||
|
|
||||||
# ==================== AI 命令系统配置 ====================
|
# ==================== AI 命令系统配置 ====================
|
||||||
ai:
|
ai:
|
||||||
# 是否启用 AI 功能
|
# 是否启用 AI 功能
|
||||||
|
|||||||
Reference in New Issue
Block a user