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 797cf62c..ccd1fc57 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 @@ -236,18 +236,27 @@ public class StrategyConfig implements Serializable { return this; } - public boolean isSupportGenerate(String table) { - if (unGenerateTables != null && unGenerateTables.contains(table)) { - return false; - } + public boolean isSupportGenerate(String 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; } } diff --git a/mybatis-flex-codegen/src/test/java/com/mybatisflex/codegen/config/StrategyConfigTest.java b/mybatis-flex-codegen/src/test/java/com/mybatisflex/codegen/config/StrategyConfigTest.java new file mode 100644 index 00000000..dd5e09fe --- /dev/null +++ b/mybatis-flex-codegen/src/test/java/com/mybatisflex/codegen/config/StrategyConfigTest.java @@ -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("测试失败"); + } + } +}