From 5fa2e08aad7bbcc93a870e9c355785d3a0f939d7 Mon Sep 17 00:00:00 2001 From: "Ray.Hao" <1490493387@qq.com> Date: Wed, 3 Dec 2025 09:49:54 +0800 Subject: [PATCH] =?UTF-8?q?feat(config):=20=E6=94=AF=E6=8C=81=E5=A4=9A?= =?UTF-8?q?=E6=95=B0=E6=8D=AE=E5=BA=93=E7=B1=BB=E5=9E=8B=E9=85=8D=E7=BD=AE?= =?UTF-8?q?=E5=8F=8A=E5=8A=A8=E6=80=81=E5=88=86=E9=A1=B5=E6=96=B9=E8=A8=80?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../com/youlai/boot/config/MybatisConfig.java | 18 +++++++++-- src/main/resources/application-dev.yml | 19 +++++++++++ src/main/resources/application-prod.yml | 32 +++++++++++++------ 3 files changed, 56 insertions(+), 13 deletions(-) diff --git a/src/main/java/com/youlai/boot/config/MybatisConfig.java b/src/main/java/com/youlai/boot/config/MybatisConfig.java index a3711fbf..7cc08b39 100644 --- a/src/main/java/com/youlai/boot/config/MybatisConfig.java +++ b/src/main/java/com/youlai/boot/config/MybatisConfig.java @@ -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,16 +22,27 @@ import org.springframework.transaction.annotation.EnableTransactionManagement; @EnableTransactionManagement public class MybatisConfig { + @Value("${app.db-type:mysql}") + private String dbType; + /** * 分页插件和数据权限插件 */ @Bean public MybatisPlusInterceptor mybatisPlusInterceptor() { 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; } diff --git a/src/main/resources/application-dev.yml b/src/main/resources/application-dev.yml index 8af66727..54a00f90 100644 --- a/src/main/resources/application-dev.yml +++ b/src/main/resources/application-dev.yml @@ -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: diff --git a/src/main/resources/application-prod.yml b/src/main/resources/application-prod.yml index fa9e9e63..b92bcc1a 100644 --- a/src/main/resources/application-prod.yml +++ b/src/main/resources/application-prod.yml @@ -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 @@ -95,19 +108,19 @@ mybatis-plus: security: session: type: jwt # 会话方式 [jwt|redis-token] - access-token-time-to-live: 7200 # 访问令牌 有效期(单位:秒),默认 2 小时,-1 表示永不过期 - refresh-token-time-to-live: 604800 # 刷新令牌有效期(单位:秒),默认 7 天,-1 表示永不过期 + access-token-time-to-live: 7200 # 访问令牌 有效期(单位:秒),默认 2 小时,-1 表示永不过期 + refresh-token-time-to-live: 604800 # 刷新令牌有效期(单位:秒),默认 7 天,-1 表示永不过期 jwt: secret-key: SecretKey012345678901234567890123456789012345678901234567890123456789 # JWT密钥(HS256算法至少32字符) redis-token: allow-multi-login: true # 是否允许多设备登录 # 安全白名单路径,仅跳过 AuthorizationFilter 过滤器,还是会走 Spring Security 的其他过滤器(CSRF、CORS等) ignore-urls: - - /api/v1/auth/login/** # 登录接口(账号密码登录、手机验证码登录和微信登录) - - /api/v1/auth/captcha # 验证码获取接口 - - /api/v1/auth/refresh-token # 刷新令牌接口 + - /api/v1/auth/login/** # 登录接口(账号密码登录、手机验证码登录和微信登录) + - /api/v1/auth/captcha # 验证码获取接口 + - /api/v1/auth/refresh-token # 刷新令牌接口 - //api/v1/auth/wx/miniapp/code-login # 微信小程序code登陆 - - /ws/** # WebSocket接口 + - /ws/** # WebSocket接口 # 非安全端点路径,完全绕过 Spring Security 的过滤器 unsecured-urls: - ${springdoc.swagger-ui.path} @@ -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 @@ -185,9 +198,9 @@ springdoc: # knife4j 接口文档配置 knife4j: # 是否开启 Knife4j 增强功能 - enable: true # 设置为 true 表示开启增强功能 + enable: true # 设置为 true 表示开启增强功能 # 生产环境配置 - production: false # 设置为 true 表示在生产环境中不显示文档,为 false 表示显示文档(通常在开发环境中使用) + production: false # 设置为 true 表示在生产环境中不显示文档,为 false 表示显示文档(通常在开发环境中使用) setting: language: zh_cn @@ -243,7 +256,6 @@ wx: app-id: xxxxxx app-secret: xxxxxx - # ==================== AI 命令系统配置 ==================== ai: # 是否启用 AI 功能