Search in sources :

Example 61 with AutoGenerator

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();
}
Also used : HashMap(java.util.HashMap) AutoGenerator(com.baomidou.mybatisplus.generator.AutoGenerator) Test(org.junit.jupiter.api.Test)

Example 62 with AutoGenerator

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();
}
Also used : HashMap(java.util.HashMap) AutoGenerator(com.baomidou.mybatisplus.generator.AutoGenerator) Test(org.junit.jupiter.api.Test)

Example 63 with AutoGenerator

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();
}
Also used : HashMap(java.util.HashMap) AutoGenerator(com.baomidou.mybatisplus.generator.AutoGenerator) Test(org.junit.jupiter.api.Test)

Example 64 with AutoGenerator

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();
}
Also used : Column(com.baomidou.mybatisplus.generator.fill.Column) Property(com.baomidou.mybatisplus.generator.fill.Property) AutoGenerator(com.baomidou.mybatisplus.generator.AutoGenerator) Test(org.junit.jupiter.api.Test)

Example 65 with AutoGenerator

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();
}
Also used : AutoGenerator(com.baomidou.mybatisplus.generator.AutoGenerator) Test(org.junit.jupiter.api.Test)

Aggregations

AutoGenerator (com.baomidou.mybatisplus.generator.AutoGenerator)69 Test (org.junit.jupiter.api.Test)25 InjectionConfig (com.baomidou.mybatisplus.generator.InjectionConfig)22 DataSourceConfig (com.baomidou.mybatisplus.generator.config.DataSourceConfig)17 GlobalConfig (com.baomidou.mybatisplus.generator.config.GlobalConfig)17 PackageConfig (com.baomidou.mybatisplus.generator.config.PackageConfig)17 StrategyConfig (com.baomidou.mybatisplus.generator.config.StrategyConfig)17 TableInfo (com.baomidou.mybatisplus.generator.config.po.TableInfo)16 FreemarkerTemplateEngine (com.baomidou.mybatisplus.generator.engine.FreemarkerTemplateEngine)16 ArrayList (java.util.ArrayList)16 HashMap (java.util.HashMap)10 MySqlTypeConvert (com.baomidou.mybatisplus.generator.config.converts.MySqlTypeConvert)7 DbColumnType (com.baomidou.mybatisplus.generator.config.rules.DbColumnType)6 VelocityTemplateEngine (com.baomidou.mybatisplus.generator.engine.VelocityTemplateEngine)6 TemplateConfig (com.baomidou.mybatisplus.generator.config.TemplateConfig)5 TableFill (com.baomidou.mybatisplus.generator.config.po.TableFill)4 FileOutConfig (com.baomidou.mybatisplus.generator.config.FileOutConfig)3 Column (com.baomidou.mybatisplus.generator.fill.Column)3 Property (com.baomidou.mybatisplus.generator.fill.Property)3 File (java.io.File)2