use of com.baomidou.mybatisplus.generator.AutoGenerator in project Hospital_BackEnd by ZJU-SE-2022-G.
the class CodeGeneratorTest method testCustomTemplatePath.
/**
* 自定义模板生成的文件路径
*
* @see OutputFile
*/
@Test
public void testCustomTemplatePath() {
// 设置自定义路径
String projectPath = System.getProperty("user.dir");
Map<OutputFile, String> pathInfo = new HashMap<>();
pathInfo.put(OutputFile.xml, projectPath + "/src/main/resources/mapper");
pathInfo.put(OutputFile.mapper, projectPath + "/src/main/java/com/segroup/hospitalsite/mapper");
pathInfo.put(OutputFile.entity, projectPath + "/src/main/java/com/segroup/hospitalsite/entity");
AutoGenerator generator = new AutoGenerator(DATA_SOURCE_CONFIG);
generator.strategy(strategyConfig().build());
generator.packageInfo(packageConfig().pathInfo(pathInfo).build());
generator.global(globalConfig().build());
generator.execute();
}
use of com.baomidou.mybatisplus.generator.AutoGenerator in project Hospital_BackEnd by ZJU-SE-2022-G.
the class CodeGeneratorTest method testCustomMap.
/**
* 自定义注入属性
*/
@Test
public void testCustomMap() {
// 设置自定义属性
Map<String, Object> map = new HashMap<>();
map.put("abc", 123);
AutoGenerator generator = new AutoGenerator(DATA_SOURCE_CONFIG);
generator.strategy(strategyConfig().build());
generator.template(templateConfig().entity("/templates/entity1.java").build());
generator.injection(injectionConfig().customMap(map).build());
generator.global(globalConfig().build());
generator.execute();
}
use of com.baomidou.mybatisplus.generator.AutoGenerator in project Hospital_BackEnd by ZJU-SE-2022-G.
the class CodeGeneratorTest method testCustomFile.
/**
* 自定义文件
* key为文件名称,value为文件路径
* 输出目录为 other
*/
@Test
public void testCustomFile() {
// 设置自定义输出文件
Map<String, String> customFile = new HashMap<>();
customFile.put("test.txt", "/templates/test.vm");
AutoGenerator generator = new AutoGenerator(DATA_SOURCE_CONFIG);
generator.strategy(strategyConfig().build());
generator.injection(injectionConfig().customFile(customFile).build());
generator.global(globalConfig().build());
generator.execute();
}
use of com.baomidou.mybatisplus.generator.AutoGenerator in project Hospital_BackEnd by ZJU-SE-2022-G.
the class CodeGeneratorTest method testVersionAndFill.
/**
* 乐观锁字段设置
* result: 新增@Version注解
* 填充字段设置
* result: 新增@TableField(value = "xxx", fill = FieldFill.xxx)注解
*/
@Test
public void testVersionAndFill() {
AutoGenerator generator = new AutoGenerator(DATA_SOURCE_CONFIG);
generator.strategy(strategyConfig().entityBuilder().versionColumnName(// 基于数据库字段
"version").versionPropertyName(// 基于模型属性
"version").addTableFills(// 基于数据库字段填充
new Column("create_time", FieldFill.INSERT)).addTableFills(// 基于模型属性填充
new Property("updateTime", FieldFill.INSERT_UPDATE)).build());
generator.global(globalConfig().build());
generator.execute();
}
use of com.baomidou.mybatisplus.generator.AutoGenerator in project Hospital_BackEnd by ZJU-SE-2022-G.
the class CodeGeneratorTest method testFieldSuffix.
/**
* 过滤字段后缀(前缀同理,支持多个)
* result: deleted_flag -> deleted
*/
@Test
public void testFieldSuffix() {
AutoGenerator generator = new AutoGenerator(DATA_SOURCE_CONFIG);
generator.strategy(strategyConfig().addFieldSuffix("_flag").build());
generator.global(globalConfig().build());
generator.execute();
}
Aggregations