use of com.baomidou.mybatisplus.generator.InjectionConfig 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.InjectionConfig in project longmarch by yuyueqty.
the class CodeGenerator method getInjectionConfig.
/**
* 自定义配置
*
* @return
*/
public InjectionConfig getInjectionConfig(PackageConfig pc) {
InjectionConfig cfg = new InjectionConfig() {
@Override
public void initMap() {
// to do nothing
}
};
// 如果模板引擎是 freemarker
String templatePath = "/templates/mapper.xml.ftl";
// 如果模板引擎是 velocity
// String templatePath = "/templates/mapper.xml.vm";
// 自定义输出配置
List<FileOutConfig> focList = new ArrayList<>();
// 自定义配置会被优先输出
focList.add(new FileOutConfig(templatePath) {
@Override
public String outputFile(TableInfo tableInfo) {
// 自定义输出文件名 , 如果你 Entity 设置了前后缀、此处注意 xml 的名称会跟着发生变化!!
return projectPath + "/src/main/resources/mapper/" + pc.getModuleName() + "/" + tableInfo.getEntityName() + "Mapper" + StringPool.DOT_XML;
}
});
cfg.setFileOutConfigList(focList);
return cfg;
}
use of com.baomidou.mybatisplus.generator.InjectionConfig in project longmarch by yuyueqty.
the class GeneratorCodeEngine method buildInjectionConfig.
private InjectionConfig buildInjectionConfig(String tableName) {
InjectionConfig injectionConfig = new InjectionConfig() {
@Override
public void initMap() {
}
};
List<FileOutConfig> fileOutConfigList = new ArrayList<>();
fileOutConfigList.add(new FileOutConfig("/generator/index.vue.ftl") {
@Override
public String outputFile(TableInfo tableInfo) {
return String.format("%s/page/index.vue", projectPath);
}
});
fileOutConfigList.add(new FileOutConfig("/generator/api.js.ftl") {
@Override
public String outputFile(TableInfo tableInfo) {
return String.format("%s/page/%sApi.js", projectPath, tableInfo.getEntityName());
}
});
fileOutConfigList.add(new FileOutConfig("/generator/lang_zh.js.ftl") {
@Override
public String outputFile(TableInfo tableInfo) {
return String.format("%s/page/lang_zh.js", projectPath);
}
});
fileOutConfigList.add(new FileOutConfig("/generator/lang_en.js.ftl") {
@Override
public String outputFile(TableInfo tableInfo) {
return String.format("%s/page/lang_en.js", projectPath);
}
});
fileOutConfigList.add(new FileOutConfig("/generator/longmarch.sql.ftl") {
@Override
public String outputFile(TableInfo tableInfo) {
return String.format("%s/sql/%s.sql", projectPath, tableName);
}
});
injectionConfig.setFileOutConfigList(fileOutConfigList);
return injectionConfig;
}
use of com.baomidou.mybatisplus.generator.InjectionConfig in project mall-learning by macrozheng.
the class MyBatisPlusGenerator method initInjectionConfig.
/**
* 初始化自定义配置
*/
private static InjectionConfig initInjectionConfig(String projectPath, String moduleName) {
// 自定义配置
InjectionConfig injectionConfig = new InjectionConfig() {
@Override
public void initMap() {
// 可用于自定义属性
}
};
// 模板引擎是Velocity
String templatePath = "/templates/mapper.xml.vm";
// 自定义输出配置
List<FileOutConfig> focList = new ArrayList<>();
// 自定义配置会被优先输出
focList.add(new FileOutConfig(templatePath) {
@Override
public String outputFile(TableInfo tableInfo) {
// 自定义输出文件名 , 如果你 Entity 设置了前后缀、此处注意 xml 的名称会跟着发生变化!!
return projectPath + "/src/main/resources/mapper/" + moduleName + "/" + tableInfo.getEntityName() + "Mapper" + StringPool.DOT_XML;
}
});
injectionConfig.setFileOutConfigList(focList);
return injectionConfig;
}
use of com.baomidou.mybatisplus.generator.InjectionConfig in project springboot-learning by lyb-geek.
the class CodeGeneratorUtils method getInjectionConfig.
/**
* InjectionConfig配置
* @param codeGeneratorHelper
* @return
*/
private static InjectionConfig getInjectionConfig(PackageConfig pc, CodeGeneratorHelper codeGeneratorHelper, String projectPath) {
InjectionConfig cfg = new InjectionConfig() {
@Override
public void initMap() {
// to do nothing
}
};
String templatePath = "/templates/mapper.xml.ftl";
List<FileOutConfig> focList = new ArrayList<>();
focList.add(new FileOutConfig(templatePath) {
@Override
public String outputFile(TableInfo tableInfo) {
// 自定义输出文件名 , 如果你 Entity 设置了前后缀、此处注意 xml 的名称会跟着发生变化!!
return projectPath + "/src/main/resources/" + codeGeneratorHelper.getMapperXmlLoction() + "/" + pc.getModuleName().toLowerCase() + "/" + tableInfo.getEntityName() + codeGeneratorHelper.getMapperNameSuffix() + StringPool.DOT_XML;
}
});
cfg.setFileOutConfigList(focList);
return cfg;
}
Aggregations