mirror of
https://gitee.com/mybatis-flex/mybatis-flex.git
synced 2025-12-07 00:58:24 +08:00
test: 测试生成内置数据脱敏处理器键(Masks)。
This commit is contained in:
parent
b0a3b358d7
commit
e547e90dff
@ -22,6 +22,7 @@ import com.mybatisflex.codegen.config.GlobalConfig;
|
||||
import com.mybatisflex.codegen.config.TableConfig;
|
||||
import com.mybatisflex.codegen.config.TableDefConfig;
|
||||
import com.mybatisflex.codegen.constant.TemplateConst;
|
||||
import com.mybatisflex.core.mask.Masks;
|
||||
import com.zaxxer.hikari.HikariDataSource;
|
||||
import org.junit.Test;
|
||||
|
||||
@ -32,7 +33,7 @@ public class GeneratorTest {
|
||||
|
||||
// @Test
|
||||
public void testCodeGen1() {
|
||||
//配置数据源
|
||||
// 配置数据源
|
||||
HikariDataSource dataSource = new HikariDataSource();
|
||||
dataSource.setJdbcUrl("jdbc:mysql://127.0.0.1:3306/flex_test?characterEncoding=utf-8");
|
||||
dataSource.setUsername("root");
|
||||
@ -40,55 +41,55 @@ public class GeneratorTest {
|
||||
|
||||
GlobalConfig globalConfig = new GlobalConfig();
|
||||
|
||||
//用户信息表,用于存放用户信息。 -> 用户信息
|
||||
// 用户信息表,用于存放用户信息。 -> 用户信息
|
||||
UnaryOperator<String> tableFormat = (e) -> e.split(",")[0].replace("表", "");
|
||||
|
||||
//设置注解生成配置
|
||||
// 设置注解生成配置
|
||||
globalConfig.setAuthor("Michael Yang");
|
||||
globalConfig.setTableCommentFormat(tableFormat);
|
||||
|
||||
//设置生成文件目录和根包
|
||||
// 设置生成文件目录和根包
|
||||
globalConfig.setSourceDir(System.getProperty("user.dir") + "/src/test/java");
|
||||
globalConfig.setMapperXmlPath(System.getProperty("user.dir") + "/src/test/java/resources/mapper");
|
||||
globalConfig.setBasePackage("com.test");
|
||||
|
||||
//设置表前缀和只生成哪些表
|
||||
// 设置表前缀和只生成哪些表
|
||||
globalConfig.setTablePrefix("sys_", "tb_");
|
||||
// globalConfig.setGenerateTable("sys_user","tb_account");
|
||||
|
||||
//设置模板路径
|
||||
// 设置模板路径
|
||||
// globalConfig.setEntityTemplatePath("D:\\Documents\\配置文件\\entity.tpl");
|
||||
|
||||
//配置生成 entity
|
||||
// 配置生成 entity
|
||||
globalConfig.setEntityGenerateEnable(true);
|
||||
globalConfig.setEntityWithLombok(true);
|
||||
globalConfig.setEntitySuperClass(BaseEntity.class);
|
||||
|
||||
//配置生成 mapper
|
||||
// 配置生成 mapper
|
||||
globalConfig.setMapperGenerateEnable(true);
|
||||
//配置生成 service
|
||||
// 配置生成 service
|
||||
globalConfig.setServiceGenerateEnable(true);
|
||||
//配置生成 serviceImpl
|
||||
// 配置生成 serviceImpl
|
||||
globalConfig.setServiceImplGenerateEnable(true);
|
||||
//配置生成 controller
|
||||
// 配置生成 controller
|
||||
globalConfig.setControllerGenerateEnable(true);
|
||||
//配置生成 tableDef
|
||||
// 配置生成 tableDef
|
||||
globalConfig.setTableDefGenerateEnable(true);
|
||||
//配置生成 mapperXml
|
||||
// 配置生成 mapperXml
|
||||
globalConfig.setMapperXmlGenerateEnable(true);
|
||||
//配置生成 package-info.java
|
||||
// 配置生成 package-info.java
|
||||
globalConfig.setPackageInfoGenerateEnable(true);
|
||||
|
||||
//通过 datasource 和 globalConfig 创建代码生成器
|
||||
// 通过 datasource 和 globalConfig 创建代码生成器
|
||||
Generator generator = new Generator(dataSource, globalConfig);
|
||||
|
||||
//开始生成代码
|
||||
// 开始生成代码
|
||||
generator.generate();
|
||||
}
|
||||
|
||||
// @Test
|
||||
public void testCodeGen2() {
|
||||
//配置数据源
|
||||
// 配置数据源
|
||||
HikariDataSource dataSource = new HikariDataSource();
|
||||
dataSource.setJdbcUrl("jdbc:mysql://127.0.0.1:3306/test?characterEncoding=utf-8");
|
||||
dataSource.setUsername("root");
|
||||
@ -96,69 +97,69 @@ public class GeneratorTest {
|
||||
|
||||
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");
|
||||
|
||||
//设置模板路径
|
||||
//globalConfig.getTemplateConfig()
|
||||
// 设置模板路径
|
||||
// globalConfig.getTemplateConfig()
|
||||
// .setEntity("D:\\Documents\\配置文件\\entity.tpl");
|
||||
|
||||
//配置生成 entity
|
||||
// 配置生成 entity
|
||||
globalConfig.enableEntity()
|
||||
.setOverwriteEnable(true)
|
||||
.setWithLombok(true)
|
||||
.setWithSwagger(true)
|
||||
.setSuperClass(BaseEntity.class);
|
||||
|
||||
//配置生成 mapper
|
||||
// 配置生成 mapper
|
||||
globalConfig.enableMapper();
|
||||
//配置生成 service
|
||||
// 配置生成 service
|
||||
globalConfig.enableService();
|
||||
//配置生成 serviceImpl
|
||||
// 配置生成 serviceImpl
|
||||
globalConfig.enableServiceImpl()
|
||||
// .setSuperClass(CacheableServiceImpl.class)
|
||||
.setCacheExample(true);
|
||||
//配置生成 controller
|
||||
// 配置生成 controller
|
||||
globalConfig.enableController();
|
||||
//配置生成 tableDef
|
||||
// 配置生成 tableDef
|
||||
globalConfig.enableTableDef();
|
||||
//配置生成 mapperXml
|
||||
// 配置生成 mapperXml
|
||||
globalConfig.enableMapperXml();
|
||||
//配置生成 package-info.java
|
||||
// 配置生成 package-info.java
|
||||
globalConfig.enablePackageInfo();
|
||||
|
||||
//通过 datasource 和 globalConfig 创建代码生成器
|
||||
// 通过 datasource 和 globalConfig 创建代码生成器
|
||||
Generator generator = new Generator(dataSource, globalConfig);
|
||||
|
||||
//开始生成代码
|
||||
// 开始生成代码
|
||||
generator.generate();
|
||||
}
|
||||
|
||||
// @Test
|
||||
public void testCodeGen3() {
|
||||
//配置数据源
|
||||
// 配置数据源
|
||||
HikariDataSource dataSource = new HikariDataSource();
|
||||
dataSource.setJdbcUrl("jdbc:mysql://127.0.0.1:3306/test?characterEncoding=utf-8");
|
||||
dataSource.setUsername("root");
|
||||
dataSource.setPassword("123456");
|
||||
|
||||
//通过 datasource 和 globalConfig 创建代码生成器
|
||||
// 通过 datasource 和 globalConfig 创建代码生成器
|
||||
new Generator(dataSource, globalConfig()).generate();
|
||||
new Generator(dataSource, globalConfig()).generate();
|
||||
new Generator(dataSource, globalConfig()).generate();
|
||||
@ -167,18 +168,18 @@ public class GeneratorTest {
|
||||
private GlobalConfig globalConfig() {
|
||||
GlobalConfig globalConfig = new GlobalConfig();
|
||||
|
||||
//用户信息表,用于存放用户信息。 -> 用户信息
|
||||
// 用户信息表,用于存放用户信息。 -> 用户信息
|
||||
UnaryOperator<String> tableFormat = (e) -> e.split(",")[0].replace("表", "");
|
||||
//属性添加句号
|
||||
// 属性添加句号
|
||||
UnaryOperator<String> columnFormat = (e) -> e.concat("。");
|
||||
|
||||
//设置注解生成配置
|
||||
// 设置注解生成配置
|
||||
globalConfig.getJavadocConfig()
|
||||
.setAuthor("王帅")
|
||||
.setTableCommentFormat(tableFormat)
|
||||
.setColumnCommentFormat(columnFormat);
|
||||
|
||||
//设置生成文件目录和根包
|
||||
// 设置生成文件目录和根包
|
||||
globalConfig.getPackageConfig()
|
||||
.setSourceDir(System.getProperty("user.dir") + "/src/test/java")
|
||||
.setMapperXmlPath(System.getProperty("user.dir") + "/src/test/java/resources/mapper")
|
||||
@ -196,14 +197,14 @@ public class GeneratorTest {
|
||||
logicDelete.setColumnName("del_flag");
|
||||
logicDelete.setLogicDelete(true);
|
||||
|
||||
//设置表前缀和只生成哪些表
|
||||
// 设置表前缀和只生成哪些表
|
||||
globalConfig.getStrategyConfig()
|
||||
.setTablePrefix("sys_")
|
||||
.setGenerateTable("sys_user")
|
||||
.setColumnConfig(logicDelete)
|
||||
.setTableConfig(tableConfig);
|
||||
|
||||
//配置生成 tableDef
|
||||
// 配置生成 tableDef
|
||||
globalConfig.enableTableDef()
|
||||
.setInstanceSuffix("Def")
|
||||
.setPropertiesNameStyle(TableDefConfig.NameStyle.LOWER_CAMEL_CASE)
|
||||
@ -270,10 +271,10 @@ public class GeneratorTest {
|
||||
globalConfig.enableService();
|
||||
globalConfig.enableServiceImpl();
|
||||
|
||||
//通过 datasource 和 globalConfig 创建代码生成器
|
||||
// 通过 datasource 和 globalConfig 创建代码生成器
|
||||
Generator generator = new Generator(dataSource, globalConfig);
|
||||
|
||||
//开始生成代码
|
||||
// 开始生成代码
|
||||
generator.generate();
|
||||
}
|
||||
|
||||
@ -317,9 +318,14 @@ public class GeneratorTest {
|
||||
.setColumnName("update_time")
|
||||
.setOnUpdateValue("NOW()");
|
||||
|
||||
ColumnConfig userNameConfig = ColumnConfig.create()
|
||||
.setColumnName("user_name")
|
||||
.setMaskType(Masks.CHINESE_NAME);
|
||||
|
||||
// sys_user 表单独配置
|
||||
TableConfig userTableConfig = TableConfig.create()
|
||||
.setTableName("sys_user")
|
||||
.setColumnConfig(userNameConfig)
|
||||
.setColumnConfig(userColumnConfig);
|
||||
|
||||
// 全局字段配置
|
||||
@ -335,14 +341,14 @@ public class GeneratorTest {
|
||||
|
||||
// 配置生成 entity
|
||||
globalConfig.enableEntity()
|
||||
.setAlwaysGenColumnAnnotation(true)
|
||||
// .setAlwaysGenColumnAnnotation(true)
|
||||
.setOverwriteEnable(true)
|
||||
.setWithLombok(true);
|
||||
|
||||
//通过 datasource 和 globalConfig 创建代码生成器
|
||||
// 通过 datasource 和 globalConfig 创建代码生成器
|
||||
Generator generator = new Generator(dataSource, globalConfig);
|
||||
|
||||
//开始生成代码
|
||||
// 开始生成代码
|
||||
generator.generate();
|
||||
}
|
||||
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user