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();
}
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();
}
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();
}
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();
}
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();
}
Aggregations