From 1c9d3f6a961d02dc3435d85afd34589a8e946154 Mon Sep 17 00:00:00 2001 From: "home\\cuiyuan" Date: Mon, 3 Mar 2025 23:40:48 +0800 Subject: [PATCH] =?UTF-8?q?=E5=A2=9E=E5=8A=A0=E5=85=A8=E5=B1=80=E5=BF=BD?= =?UTF-8?q?=E7=95=A5=20schema?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../java/com/mybatisflex/core/FlexGlobalConfig.java | 13 +++++++++++++ .../mybatisflex/core/table/TableInfoFactory.java | 12 ++++++++---- .../spring/boot/MybatisFlexProperties.java | 13 +++++++++++++ 3 files changed, 34 insertions(+), 4 deletions(-) diff --git a/mybatis-flex-core/src/main/java/com/mybatisflex/core/FlexGlobalConfig.java b/mybatis-flex-core/src/main/java/com/mybatisflex/core/FlexGlobalConfig.java index 3dc26379..de7a155f 100644 --- a/mybatis-flex-core/src/main/java/com/mybatisflex/core/FlexGlobalConfig.java +++ b/mybatis-flex-core/src/main/java/com/mybatisflex/core/FlexGlobalConfig.java @@ -110,6 +110,11 @@ public class FlexGlobalConfig { */ private String versionColumn; + /** + * 全局忽略 @Table 中配置的 schema + */ + private boolean ignoreSchema = false; + /** * 未匹配列处理器 */ @@ -329,6 +334,14 @@ public class FlexGlobalConfig { this.versionColumn = versionColumn; } + public boolean isIgnoreSchema() { + return ignoreSchema; + } + + public void setIgnoreSchema(boolean ignoreSchema) { + this.ignoreSchema = ignoreSchema; + } + public UnMappedColumnHandler getUnMappedColumnHandler() { return unMappedColumnHandler; } diff --git a/mybatis-flex-core/src/main/java/com/mybatisflex/core/table/TableInfoFactory.java b/mybatis-flex-core/src/main/java/com/mybatisflex/core/table/TableInfoFactory.java index b11d2a69..259afa7b 100644 --- a/mybatis-flex-core/src/main/java/com/mybatisflex/core/table/TableInfoFactory.java +++ b/mybatis-flex-core/src/main/java/com/mybatisflex/core/table/TableInfoFactory.java @@ -235,6 +235,8 @@ public class TableInfoFactory { Reflector reflector = Reflectors.of(entityClass); tableInfo.setReflector(reflector); + FlexGlobalConfig config = FlexGlobalConfig.getDefaultConfig(); + // 初始化表名 Table table = entityClass.getAnnotation(Table.class); if (table == null) { @@ -242,7 +244,9 @@ public class TableInfoFactory { if (vo != null) { TableInfo refTableInfo = ofEntityClass(vo.value()); // 设置 VO 类对应的真实的表名 - tableInfo.setSchema(refTableInfo.getSchema()); + if (!config.isIgnoreSchema()) { + tableInfo.setSchema(refTableInfo.getSchema()); + } tableInfo.setTableName(refTableInfo.getTableName()); // 将 @Table 注解的属性复制到 VO 类当中 if (vo.copyTableProps()) { @@ -260,7 +264,9 @@ public class TableInfoFactory { tableInfo.setTableName(tableName); } } else { - tableInfo.setSchema(table.schema()); + if (!config.isIgnoreSchema()) { + tableInfo.setSchema(table.schema()); + } tableInfo.setTableName(table.value()); tableInfo.setCamelToUnderline(table.camelToUnderline()); tableInfo.setComment(table.comment()); @@ -317,8 +323,6 @@ public class TableInfoFactory { List entityFields = getColumnFields(entityClass); - FlexGlobalConfig config = FlexGlobalConfig.getDefaultConfig(); - TypeHandlerRegistry typeHandlerRegistry = null; if (config.getConfiguration() != null) { typeHandlerRegistry = config.getConfiguration().getTypeHandlerRegistry(); diff --git a/mybatis-flex-spring-boot-starter/src/main/java/com/mybatisflex/spring/boot/MybatisFlexProperties.java b/mybatis-flex-spring-boot-starter/src/main/java/com/mybatisflex/spring/boot/MybatisFlexProperties.java index 7fbf5843..39d1ac3c 100644 --- a/mybatis-flex-spring-boot-starter/src/main/java/com/mybatisflex/spring/boot/MybatisFlexProperties.java +++ b/mybatis-flex-spring-boot-starter/src/main/java/com/mybatisflex/spring/boot/MybatisFlexProperties.java @@ -823,6 +823,10 @@ public class MybatisFlexProperties { */ private String versionColumn; + /** + * 全局忽略 @Table 中配置的 schema + */ + private boolean ignoreSchema = false; public boolean isPrintBanner() { return printBanner; @@ -896,6 +900,14 @@ public class MybatisFlexProperties { this.versionColumn = versionColumn; } + public boolean isIgnoreSchema() { + return ignoreSchema; + } + + public void setIgnoreSchema(boolean ignoreSchema) { + this.ignoreSchema = ignoreSchema; + } + void applyTo(FlexGlobalConfig target) { PropertyMapper mapper = PropertyMapper.get().alwaysApplyingWhenNonNull(); mapper.from(isPrintBanner()).to(target::setPrintBanner); @@ -907,6 +919,7 @@ public class MybatisFlexProperties { mapper.from(getLogicDeleteColumn()).to(target::setLogicDeleteColumn); mapper.from(getVersionColumn()).to(target::setVersionColumn); mapper.from(getTenantColumn()).to(target::setTenantColumn); + mapper.from(isIgnoreSchema()).to(target::setIgnoreSchema); } }