diff --git a/mybatis-flex-codegen/src/main/java/com/mybatisflex/codegen/config/ColumnConfigFactory.java b/mybatis-flex-codegen/src/main/java/com/mybatisflex/codegen/config/ColumnConfigFactory.java new file mode 100644 index 00000000..c0bce35b --- /dev/null +++ b/mybatis-flex-codegen/src/main/java/com/mybatisflex/codegen/config/ColumnConfigFactory.java @@ -0,0 +1,21 @@ +/* + * Copyright (c) 2022-2025, Mybatis-Flex (fuhai999@gmail.com). + *

+ * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + *

+ * http://www.apache.org/licenses/LICENSE-2.0 + *

+ * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +package com.mybatisflex.codegen.config; + +public interface ColumnConfigFactory { + + ColumnConfig getColumnConfig(String tableName, String columnName); +} diff --git a/mybatis-flex-codegen/src/main/java/com/mybatisflex/codegen/config/GlobalConfig.java b/mybatis-flex-codegen/src/main/java/com/mybatisflex/codegen/config/GlobalConfig.java index 7c994443..1c99efbb 100644 --- a/mybatis-flex-codegen/src/main/java/com/mybatisflex/codegen/config/GlobalConfig.java +++ b/mybatis-flex-codegen/src/main/java/com/mybatisflex/codegen/config/GlobalConfig.java @@ -670,6 +670,14 @@ public class GlobalConfig implements Serializable { return getStrategyConfig().getColumnConfig(tableName, columnName); } + public ColumnConfigFactory getColumnConfigFactory() { + return getStrategyConfig().getColumnConfigFactory(); + } + + public void setColumnConfigFactory(ColumnConfigFactory columnConfigFactory) { + getStrategyConfig().setColumnConfigFactory(columnConfigFactory); + } + /** * @see StrategyConfig#isGenerateForView() */ diff --git a/mybatis-flex-codegen/src/main/java/com/mybatisflex/codegen/config/StrategyConfig.java b/mybatis-flex-codegen/src/main/java/com/mybatisflex/codegen/config/StrategyConfig.java index 13b2581b..25973551 100644 --- a/mybatis-flex-codegen/src/main/java/com/mybatisflex/codegen/config/StrategyConfig.java +++ b/mybatis-flex-codegen/src/main/java/com/mybatisflex/codegen/config/StrategyConfig.java @@ -70,6 +70,11 @@ public class StrategyConfig implements Serializable { */ private Map columnConfigMap; + /** + * 自定义列配置工厂。 + */ + private ColumnConfigFactory columnConfigFactory; + /** * 需要生成的表在哪个模式下 */ @@ -154,8 +159,12 @@ public class StrategyConfig implements Serializable { public ColumnConfig getColumnConfig(String tableName, String columnName) { ColumnConfig columnConfig = null; + if (columnConfigFactory != null) { + columnConfig = columnConfigFactory.getColumnConfig(tableName, columnName); + } + TableConfig tableConfig = getTableConfig(tableName); - if (tableConfig != null) { + if (columnConfig == null && tableConfig != null) { columnConfig = tableConfig.getColumnConfig(columnName); } @@ -208,6 +217,14 @@ public class StrategyConfig implements Serializable { return this; } + public ColumnConfigFactory getColumnConfigFactory() { + return columnConfigFactory; + } + + public void setColumnConfigFactory(ColumnConfigFactory columnConfigFactory) { + this.columnConfigFactory = columnConfigFactory; + } + /** * 设置生成哪些表。 */ @@ -244,13 +261,13 @@ public class StrategyConfig implements Serializable { public boolean isSupportGenerate(String table) { - if (table == null || table.isEmpty() ){ + if (table == null || table.isEmpty()) { return true; } if (unGenerateTables != null) { for (String unGenerateTable : unGenerateTables) { // 使用正则表达式匹配表名 - String regex = unGenerateTable.replace("*",".*"); + String regex = unGenerateTable.replace("*", ".*"); if (table.matches(regex)) { return false; } @@ -261,7 +278,7 @@ public class StrategyConfig implements Serializable { return true; } for (String generateTable : generateTables) { - String regex = generateTable.replace("*",".*"); + String regex = generateTable.replace("*", ".*"); if (table.matches(regex)) { return true; }