Browse Source

fix: github pull/5429 新增表匹配测试用例

hubin 1 year ago
parent
commit
8fa03df3e5

+ 24 - 0
mybatis-plus-generator/src/test/java/com/baomidou/mybatisplus/generator/samples/H2CodeGeneratorTest.java

@@ -311,6 +311,30 @@ public class H2CodeGeneratorTest extends BaseGeneratorTest {
         generator.execute();
     }
 
+    /**
+     * 测试开正则匹配包含的表名
+     */
+    @Test
+    public void testAddIncludeTables() {
+        AutoGenerator generator = new AutoGenerator(DATA_SOURCE_CONFIG);
+        generator.strategy(new StrategyConfig.Builder().addInclude("^t_.*").build());
+        generator.execute();
+    }
+
+    /**
+     * 测试开正则匹配排除的表名
+     */
+    @Test
+    public void testAddExcludeTables() {
+        AutoGenerator generator = new AutoGenerator(DATA_SOURCE_CONFIG);
+        generator.strategy(new StrategyConfig.Builder().addExclude(
+            // 排除 st 结尾的表
+            ".*st$",
+            // 排除非 t_ 开头的表
+            "^(?!t_).*"
+        ).build()).execute();
+    }
+
     /**
      * 测试开启Boolean类型字段移除is前缀
      */

+ 7 - 0
mybatis-plus-generator/src/test/resources/sql/init.sql

@@ -12,3 +12,10 @@ create table `t_simple`
     update_time datetime comment '更新时间',
     primary key (id)
 ) COMMENT = '测试表';
+drop table if exists `t_test`;
+create table `t_test`
+(
+    id          int auto_increment comment 'id',
+    name        varchar(50) comment '姓名',
+    primary key (id)
+) COMMENT = '测试表';