Search in sources :

Example 46 with AutoGenerator

use of com.baomidou.mybatisplus.generator.AutoGenerator in project weather-push by yangh124.

the class H2CodeGeneratorTest method testCustomTemplateName.

/**
 * 自定义模板生成的文件名称 result: TSimple -> TSimpleEntity
 */
@Test
public void testCustomTemplateName() {
    AutoGenerator generator = new AutoGenerator(DATA_SOURCE_CONFIG);
    generator.strategy(strategyConfig().entityBuilder().formatFileName("%sEntity").mapperBuilder().formatMapperFileName("%sDao").formatXmlFileName("%sXml").controllerBuilder().formatFileName("%sAction").serviceBuilder().formatServiceFileName("%sService").formatServiceImplFileName("%sServiceImp").build());
    generator.global(globalConfig().build());
    generator.execute();
}
Also used : AutoGenerator(com.baomidou.mybatisplus.generator.AutoGenerator) Test(org.junit.jupiter.api.Test)

Example 47 with AutoGenerator

use of com.baomidou.mybatisplus.generator.AutoGenerator in project weather-push by yangh124.

the class H2CodeGeneratorTest 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 48 with AutoGenerator

use of com.baomidou.mybatisplus.generator.AutoGenerator in project weather-push by yangh124.

the class H2CodeGeneratorTest method testSimple.

/**
 * 简单生成
 */
@Test
public void testSimple() {
    AutoGenerator generator = new AutoGenerator(DATA_SOURCE_CONFIG);
    generator.strategy(strategyConfig().entityBuilder().enableLombok().idType(IdType.ASSIGN_ID).logicDeleteColumnName("is_delete").build());
    generator.global(globalConfig().build());
    generator.packageInfo(packageConfig().build());
    generator.template(templateConfig().build());
    generator.execute();
}
Also used : AutoGenerator(com.baomidou.mybatisplus.generator.AutoGenerator) Test(org.junit.jupiter.api.Test)

Example 49 with AutoGenerator

use of com.baomidou.mybatisplus.generator.AutoGenerator in project weather-push by yangh124.

the class H2CodeGeneratorTest 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)

Example 50 with AutoGenerator

use of com.baomidou.mybatisplus.generator.AutoGenerator in project weather-push by yangh124.

the class H2CodeGeneratorTest method testCustomTemplatePath.

/**
 * 自定义模板生成的文件路径
 *
 * @see OutputFile
 */
@Test
public void testCustomTemplatePath() {
    // 设置自定义路径
    Map<OutputFile, String> pathInfo = new HashMap<>();
    pathInfo.put(OutputFile.mapperXml, "D://");
    pathInfo.put(OutputFile.entity, "D://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)

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