!440 策略配置StrategyConfig支持通配符功能

Merge pull request !440 from niann/main
This commit is contained in:
Michael Yang 2024-03-21 01:18:06 +00:00 committed by Gitee
commit 4a8eb8862f
No known key found for this signature in database
GPG Key ID: 173E9B9CA92EEF8F
2 changed files with 38 additions and 6 deletions

View File

@ -236,18 +236,27 @@ public class StrategyConfig implements Serializable {
return this;
}
public boolean isSupportGenerate(String table) {
if (unGenerateTables != null && unGenerateTables.contains(table)) {
if (table == null || table.isEmpty() ){
return true;
}
if (unGenerateTables != null) {
for (String unGenerateTable : unGenerateTables) {
// 使用正则表达式匹配表名
String regex = unGenerateTable.replace("*",".*");
if (table.matches(regex)) {
return false;
}
}
}
//不配置指定比表名的情况下支持所有表
if (generateTables == null || generateTables.isEmpty()) {
return true;
}
for (String generateTable : generateTables) {
if (generateTable.equals(table)) {
String regex = generateTable.replace("*",".*");
if (table.matches(regex)) {
return true;
}
}

View File

@ -0,0 +1,23 @@
package com.mybatisflex.codegen.config;
import junit.framework.TestCase;
public class StrategyConfigTest extends TestCase {
StrategyConfig strategyConfig = new StrategyConfig();
private void init(){
strategyConfig.setUnGenerateTable("user*","sys_*","db*01");
}
public void testIsSupportGenerate() {
init();
boolean var1 = strategyConfig.isSupportGenerate("username");
boolean var2 = strategyConfig.isSupportGenerate("sys_info");
boolean var3 = strategyConfig.isSupportGenerate("db_redis_01");
boolean var4 = strategyConfig.isSupportGenerate("user");
if (var1 || var2 || var3 || !var4){
throw new RuntimeException("测试失败");
}
}
}