mirror of
https://gitee.com/mybatis-flex/mybatis-flex.git
synced 2025-12-07 00:58:24 +08:00
test: 测试支持 TableConfig 匹配全表。
This commit is contained in:
parent
4bbc2b3ed2
commit
03e5c971c6
@ -23,6 +23,7 @@ import com.mybatisflex.codegen.config.TableConfig;
|
||||
import com.mybatisflex.codegen.config.TableDefConfig;
|
||||
import com.mybatisflex.codegen.constant.TemplateConst;
|
||||
import com.zaxxer.hikari.HikariDataSource;
|
||||
import org.junit.Test;
|
||||
|
||||
import java.util.function.UnaryOperator;
|
||||
|
||||
@ -189,7 +190,7 @@ public class GeneratorTest {
|
||||
|
||||
TableConfig tableConfig = new TableConfig();
|
||||
tableConfig.setTableName("sys_user");
|
||||
tableConfig.addColumnConfig(columnConfig);
|
||||
tableConfig.setColumnConfig(columnConfig);
|
||||
|
||||
ColumnConfig logicDelete = new ColumnConfig();
|
||||
logicDelete.setColumnName("del_flag");
|
||||
@ -276,4 +277,72 @@ public class GeneratorTest {
|
||||
generator.generate();
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testCodeGen5() {
|
||||
// 配置数据源
|
||||
HikariDataSource dataSource = new HikariDataSource();
|
||||
dataSource.setJdbcUrl("jdbc:mysql://127.0.0.1:3306/test?characterEncoding=utf-8");
|
||||
dataSource.setUsername("root");
|
||||
dataSource.setPassword("12345678");
|
||||
|
||||
GlobalConfig globalConfig = new GlobalConfig();
|
||||
|
||||
// 用户信息表,用于存放用户信息。 -> 用户信息
|
||||
UnaryOperator<String> tableFormat = (e) -> e.split(",")[0].replace("表", "");
|
||||
|
||||
// 设置注解生成配置
|
||||
globalConfig.getJavadocConfig()
|
||||
.setAuthor("王帅")
|
||||
.setTableCommentFormat(tableFormat);
|
||||
|
||||
// 设置生成文件目录和根包
|
||||
globalConfig.getPackageConfig()
|
||||
.setSourceDir(System.getProperty("user.dir") + "/src/test/java")
|
||||
.setMapperXmlPath(System.getProperty("user.dir") + "/src/test/resources/mapper")
|
||||
.setBasePackage("com.test");
|
||||
|
||||
// 设置表前缀和只生成哪些表
|
||||
globalConfig.getStrategyConfig()
|
||||
.setTablePrefix("sys_")
|
||||
.setGenerateTable("sys_user", "sys_role");
|
||||
|
||||
// 全局表配置
|
||||
TableConfig tableConfig = TableConfig.builder()
|
||||
.camelToUnderline(false)
|
||||
.mapperGenerateEnable(false)
|
||||
.build();
|
||||
|
||||
// sys_user 字段单独配置
|
||||
ColumnConfig userColumnConfig = ColumnConfig.create()
|
||||
.setColumnName("update_time")
|
||||
.setOnUpdateValue("NOW()");
|
||||
|
||||
// sys_user 表单独配置
|
||||
TableConfig userTableConfig = TableConfig.create()
|
||||
.setTableName("sys_user")
|
||||
.setColumnConfig(userColumnConfig);
|
||||
|
||||
// 全局字段配置
|
||||
ColumnConfig columnConfig = ColumnConfig.builder()
|
||||
.columnName("create_time")
|
||||
.onInsertValue("NOW()")
|
||||
.build();
|
||||
|
||||
globalConfig.getStrategyConfig()
|
||||
.setTableConfig(tableConfig)
|
||||
.setTableConfig(userTableConfig)
|
||||
.setColumnConfig(columnConfig);
|
||||
|
||||
// 配置生成 entity
|
||||
globalConfig.enableEntity()
|
||||
.setOverwriteEnable(true)
|
||||
.setWithLombok(true);
|
||||
|
||||
//通过 datasource 和 globalConfig 创建代码生成器
|
||||
Generator generator = new Generator(dataSource, globalConfig);
|
||||
|
||||
//开始生成代码
|
||||
generator.generate();
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user