mirror of
https://gitee.com/mybatis-flex/mybatis-flex.git
synced 2025-12-06 16:48: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);
|
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()
|
||||||
*/
|
*/
|
||||||
|
|||||||
@ -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;
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 设置生成哪些表。
|
* 设置生成哪些表。
|
||||||
*/
|
*/
|
||||||
@ -244,13 +261,13 @@ public class StrategyConfig implements Serializable {
|
|||||||
|
|
||||||
|
|
||||||
public boolean isSupportGenerate(String table) {
|
public boolean isSupportGenerate(String table) {
|
||||||
if (table == null || table.isEmpty() ){
|
if (table == null || table.isEmpty()) {
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
if (unGenerateTables != null) {
|
if (unGenerateTables != null) {
|
||||||
for (String unGenerateTable : unGenerateTables) {
|
for (String unGenerateTable : unGenerateTables) {
|
||||||
// 使用正则表达式匹配表名
|
// 使用正则表达式匹配表名
|
||||||
String regex = unGenerateTable.replace("*",".*");
|
String regex = unGenerateTable.replace("*", ".*");
|
||||||
if (table.matches(regex)) {
|
if (table.matches(regex)) {
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
@ -261,7 +278,7 @@ public class StrategyConfig implements Serializable {
|
|||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
for (String generateTable : generateTables) {
|
for (String generateTable : generateTables) {
|
||||||
String regex = generateTable.replace("*",".*");
|
String regex = generateTable.replace("*", ".*");
|
||||||
if (table.matches(regex)) {
|
if (table.matches(regex)) {
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user