Search in sources :

Example 51 with AutoGenerator

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

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

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

the class H2CodeGeneratorTest method testLogicDeleteAndIgnoreColumn.

/**
 * 逻辑删除字段设置 result: 新增@TableLogic注解 忽略字段设置 result: 不生成
 */
@Test
public void testLogicDeleteAndIgnoreColumn() {
    AutoGenerator generator = new AutoGenerator(DATA_SOURCE_CONFIG);
    generator.strategy(// 基于数据库字段
    strategyConfig().entityBuilder().logicDeleteColumnName("deleted").logicDeletePropertyName(// 基于模型属性
    "deleteFlag").addIgnoreColumns(// 基于数据库字段
    "age").build());
    generator.global(globalConfig().build());
    generator.execute();
}
Also used : AutoGenerator(com.baomidou.mybatisplus.generator.AutoGenerator) Test(org.junit.jupiter.api.Test)

Example 53 with AutoGenerator

use of com.baomidou.mybatisplus.generator.AutoGenerator in project springboot-learning by lyb-geek.

the class CodeGeneratorUtils method execute.

/**
 * 代码生成逻辑
 * @param codeGeneratorHelper
 * @throws Exception
 */
public static void execute(CodeGeneratorHelper codeGeneratorHelper) throws Exception {
    // 代码生成器
    AutoGenerator mpg = new AutoGenerator();
    // 项目路径
    String projectPath = codeGeneratorHelper.getProjectPath();
    if (StringUtils.isBlank(projectPath)) {
        projectPath = getProjectPath();
        System.out.println("-----------------项目根路径未配置将使用默认配置路径--->" + projectPath + "----------------");
    }
    // 全局配置
    GlobalConfig gc = getGlobalConfig(codeGeneratorHelper, projectPath);
    mpg.setGlobalConfig(gc);
    // 数据源配置
    DataSourceConfig dsc = getDataSourceConfig(codeGeneratorHelper);
    mpg.setDataSource(dsc);
    // 包配置
    PackageConfig pc = getPackageConfig(codeGeneratorHelper);
    mpg.setPackageInfo(pc);
    InjectionConfig cfg = getInjectionConfig(pc, codeGeneratorHelper, projectPath);
    mpg.setCfg(cfg);
    // 配置模板
    TemplateConfig templateConfig = new TemplateConfig();
    templateConfig.setXml(null);
    mpg.setTemplate(templateConfig);
    // 策略配置
    StrategyConfig strategy = getStrategyConfig(codeGeneratorHelper);
    mpg.setStrategy(strategy);
    mpg.setTemplateEngine(new FreemarkerTemplateEngine());
    mpg.execute();
}
Also used : InjectionConfig(com.baomidou.mybatisplus.generator.InjectionConfig) FreemarkerTemplateEngine(com.baomidou.mybatisplus.generator.engine.FreemarkerTemplateEngine) AutoGenerator(com.baomidou.mybatisplus.generator.AutoGenerator)

Example 54 with AutoGenerator

use of com.baomidou.mybatisplus.generator.AutoGenerator in project EVA-API by PKAQ-LAB.

the class SingleCodeGenerator method main.

/**
 * <p>
 * 读取控制台内容
 * </p>
 */
public static void main(String[] args) {
    // 代码生成器
    AutoGenerator mpg = new AutoGenerator();
    // 全局配置
    GlobalConfig gc = new GlobalConfig();
    String projectPath = System.getProperty("user.dir");
    gc.setOutputDir(projectPath + "/eva-generator/src/main/java");
    gc.setAuthor(AUTHOR);
    // 是否打开输出目录
    gc.setOpen(false);
    // 启用swagger
    gc.setSwagger2(true);
    gc.setServiceName("%sService");
    // 不生成serviceImpl类
    gc.setServiceImplName(null);
    gc.setControllerName("%sCtrl");
    gc.setEntityName("%sEntity");
    mpg.setGlobalConfig(gc);
    DataSourceConfig dsc = new DataSourceConfig();
    dsc.setUrl(URL);
    dsc.setDriverName(DRIVER);
    dsc.setUsername(USER);
    dsc.setPassword(PWD);
    mpg.setDataSource(dsc);
    // 包配置
    PackageConfig pc = new PackageConfig();
    // TODO 模块包名
    pc.setModuleName("biz");
    pc.setParent(BASEPKG);
    mpg.setPackageInfo(pc);
    // 模板配置
    TemplateConfig templateConfig = new TemplateConfig();
    // xml模板
    templateConfig.setXml(null);
    // entity模板
    templateConfig.setEntity("/templates/mybatis/listModal/java/entity.java");
    // controller模板
    templateConfig.setController("templates/mybatis/listModal/java/controller.java");
    // mapper模板
    templateConfig.setMapper("/templates/mybatis/listModal/java/mapper.java");
    // service模板
    templateConfig.setService("/templates/mybatis/listModal/java/service.java");
    templateConfig.setServiceImpl(null);
    // 自定义配置
    InjectionConfig cfg = new InjectionConfig() {

        @Override
        public void initMap() {
            Map<String, Object> map = new HashMap<>(1);
            map.put("sysName", SYS_NAME);
            this.setMap(map);
        }
    };
    mpg.setCfg(cfg);
    mpg.setTemplate(templateConfig);
    // 策略配置
    StrategyConfig strategy = new StrategyConfig();
    strategy.setNaming(NamingStrategy.underline_to_camel);
    strategy.setColumnNaming(NamingStrategy.underline_to_camel);
    // 定义基类
    strategy.setSuperEntityClass("io.nerv.core.mvc.entity.mybatis.StdBaseEntity");
    strategy.setSuperControllerClass("io.nerv.core.mvc.ctrl.mybatis.StdBaseCtrl");
    strategy.setSuperMapperClass("com.baomidou.mybatisplus.core.mapper.BaseMapper");
    strategy.setSuperServiceClass("io.nerv.core.mvc.service.mybatis.StdBaseService");
    strategy.setEntityLombokModel(true);
    strategy.setRestControllerStyle(true);
    strategy.setControllerMappingHyphenStyle(true);
    // TODO 表名
    strategy.setInclude("log_biz");
    strategy.setSuperEntityColumns("ID", "CREATE_BY", "GMT_CREATE", "MODIFY_BY", "GMT_MODIFY", "REMARK");
    // TODO 去除表前缀
    strategy.setTablePrefix("log_");
    mpg.setStrategy(strategy);
    mpg.setTemplateEngine(new VelocityTemplateEngine());
    mpg.execute();
}
Also used : HashMap(java.util.HashMap) VelocityTemplateEngine(com.baomidou.mybatisplus.generator.engine.VelocityTemplateEngine) InjectionConfig(com.baomidou.mybatisplus.generator.InjectionConfig) AutoGenerator(com.baomidou.mybatisplus.generator.AutoGenerator)

Example 55 with AutoGenerator

use of com.baomidou.mybatisplus.generator.AutoGenerator in project heifer by galaxy-sea.

the class GeneratorCode method main.

// public static void main(String[] args) {
// System.out.println("mpw:" + AES.encrypt("jdbc:mysql://xxxxx :3306/heifer_boot?serverTimezone=UTC", "xxxxxxxxxxxxxxxx"));
// System.out.println("mpw:" + AES.encrypt("xxxxxx", "xxxxxxxxxxxxxxxx"));
// System.out.println("mpw:" + AES.encrypt("xxxxxx", "xxxxxxxxxxxxxxxx"));
// }
public static void main(String[] args) {
    // 代码生成器
    AutoGenerator mpg = new AutoGenerator();
    // 全局配置
    mpg.setGlobalConfig(globalConfig());
    // 数据源配置
    mpg.setDataSource(dataSourceConfig());
    // 包配置
    mpg.setPackageInfo(packageConfig());
    // 自定义配置
    mpg.setCfg(injectionConfig(mpg.getPackageInfo(), mpg.getDataSource()));
    // 配置模板
    mpg.setTemplate(templateConfig());
    // 策略配置
    mpg.setStrategy(strategyConfig());
    // TODO: 2021/7/2 changjin wei(魏昌进)
    mpg.setTemplateEngine(new FreemarkerTemplateEngine());
    mpg.execute();
}
Also used : FreemarkerTemplateEngine(com.baomidou.mybatisplus.generator.engine.FreemarkerTemplateEngine) AutoGenerator(com.baomidou.mybatisplus.generator.AutoGenerator)

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