feat: codegen add ColumnConfigFactory config support

This commit is contained in:
Michael Yang 2024-11-02 16:23:57 +08:00
parent 8526fcd735
commit 82d62bfa4e
3 changed files with 50 additions and 4 deletions

View File

@ -0,0 +1,21 @@
/*
* Copyright (c) 2022-2025, Mybatis-Flex (fuhai999@gmail.com).
* <p>
* 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
* <p>
* http://www.apache.org/licenses/LICENSE-2.0
* <p>
* 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);
}

View File

@ -670,6 +670,14 @@ public class GlobalConfig implements Serializable {
return getStrategyConfig().getColumnConfig(tableName, columnName); return getStrategyConfig().getColumnConfig(tableName, columnName);
} }
public ColumnConfigFactory getColumnConfigFactory() {
return getStrategyConfig().getColumnConfigFactory();
}
public void setColumnConfigFactory(ColumnConfigFactory columnConfigFactory) {
getStrategyConfig().setColumnConfigFactory(columnConfigFactory);
}
/** /**
* @see StrategyConfig#isGenerateForView() * @see StrategyConfig#isGenerateForView()
*/ */

View File

@ -70,6 +70,11 @@ public class StrategyConfig implements Serializable {
*/ */
private Map<String, ColumnConfig> columnConfigMap; private Map<String, ColumnConfig> columnConfigMap;
/**
* 自定义列配置工厂
*/
private ColumnConfigFactory columnConfigFactory;
/** /**
* 需要生成的表在哪个模式下 * 需要生成的表在哪个模式下
*/ */
@ -154,8 +159,12 @@ public class StrategyConfig implements Serializable {
public ColumnConfig getColumnConfig(String tableName, String columnName) { public ColumnConfig getColumnConfig(String tableName, String columnName) {
ColumnConfig columnConfig = null; ColumnConfig columnConfig = null;
if (columnConfigFactory != null) {
columnConfig = columnConfigFactory.getColumnConfig(tableName, columnName);
}
TableConfig tableConfig = getTableConfig(tableName); TableConfig tableConfig = getTableConfig(tableName);
if (tableConfig != null) { if (columnConfig == null && tableConfig != null) {
columnConfig = tableConfig.getColumnConfig(columnName); columnConfig = tableConfig.getColumnConfig(columnName);
} }
@ -208,6 +217,14 @@ public class StrategyConfig implements Serializable {
return this; return this;
} }
public ColumnConfigFactory getColumnConfigFactory() {
return columnConfigFactory;
}
public void setColumnConfigFactory(ColumnConfigFactory columnConfigFactory) {
this.columnConfigFactory = columnConfigFactory;
}
/** /**
* 设置生成哪些表 * 设置生成哪些表
*/ */