mirror of
https://gitee.com/mybatis-flex/mybatis-flex.git
synced 2025-12-07 00:58:24 +08:00
feat: codegen add ColumnConfigFactory config support
This commit is contained in:
parent
8526fcd735
commit
82d62bfa4e
@ -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);
|
||||
}
|
||||
@ -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()
|
||||
*/
|
||||
|
||||
@ -70,6 +70,11 @@ public class StrategyConfig implements Serializable {
|
||||
*/
|
||||
private Map<String, ColumnConfig> 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;
|
||||
}
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user