use of com.baomidou.mybatisplus.generator.InjectionConfig in project longmarch by yuyueqty.
the class GeneratorCodeEngine method buildAutoGenerator.
public AutoGenerator buildAutoGenerator(String moduleName, String tableName, List<SysGenerator> fieldGenerationConditionList) {
AutoGenerator autoSysGenerator = new AutoGenerator();
GlobalConfig globalConfig = buildGlobalConfig();
TemplateConfig templateConfig = buildTemplateConfig();
DataSourceConfig dataSourceConfig = buildDataSourceConfig();
PackageConfig packageConfig = buildPackageConfig(moduleName);
InjectionConfig injectionConfig = buildInjectionConfig(tableName);
StrategyConfig strategy = buildStrategyConfig(packageConfig, tableName);
autoSysGenerator.setGlobalConfig(globalConfig);
autoSysGenerator.setTemplate(templateConfig);
autoSysGenerator.setDataSource(dataSourceConfig);
autoSysGenerator.setPackageInfo(packageConfig);
autoSysGenerator.setCfg(injectionConfig);
autoSysGenerator.setStrategy(strategy);
autoSysGenerator.setTemplateEngine(new FkTemplateEngine(fieldGenerationConditionList));
return autoSysGenerator;
}
use of com.baomidou.mybatisplus.generator.InjectionConfig in project heifer by galaxy-sea.
the class GeneratorCode method injectionConfig.
private static InjectionConfig injectionConfig(PackageConfig packageInfo, DataSourceConfig dataSourceConfig) {
InjectionConfig cfg = new InjectionConfig() {
@Override
public void initMap() {
this.setMap(map);
// to do nothing
}
@Override
public void initTableMap(TableInfo tableInfo) {
super.initTableMap(tableInfo);
tableInfo.setComment(pattern.matcher(tableInfo.getComment()).replaceAll(""));
for (TableField field : tableInfo.getFields()) {
if (StringUtils.isNotEmpty(field.getComment())) {
field.setComment(pattern.matcher(field.getComment()).replaceAll(""));
}
}
}
};
String projectPath = System.getProperty("user.dir");
// 如果模板引擎是 freemarker
String templatePath = "generator/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 的名称会跟着发生变化!!
if (moduleName == null) {
return projectPath + "/src/main/resources/mapper/" + "" + tableInfo.getXmlName() + "Mapper" + ConstVal.XML_SUFFIX;
}
moduleName = moduleName.replace(".", "/");
return projectPath + "/src/main/resources/mapper/" + moduleName + "/" + tableInfo.getXmlName() + ConstVal.XML_SUFFIX;
}
});
cfg.setFileOutConfigList(focList);
return cfg;
}
use of com.baomidou.mybatisplus.generator.InjectionConfig in project drug by xiabud.
the class CodeGenerator method cg.
@Test
public void cg() {
// 代码生成器
AutoGenerator mpg = new AutoGenerator();
// 全局配置
GlobalConfig gc = new GlobalConfig();
String projectPath = System.getProperty("user.dir");
gc.setOutputDir(projectPath + "/src/main/java");
gc.setAuthor("xiewc");
gc.setOpen(false);
gc.setFileOverride(false);
gc.setServiceName("%sService");
// gc.setSwagger2(true); 实体属性 Swagger2 注解
mpg.setGlobalConfig(gc);
// 数据源配置
DataSourceConfig dsc = new DataSourceConfig();
// dsc.setUrl("jdbc:oracle:thin:@10.20.11.11:1521:JSGLAX1");
dsc.setUrl("jdbc:mysql://localhost:3306/drug");
dsc.setDriverName("com.mysql.cj.jdbc.Driver");
dsc.setUsername("root");
dsc.setPassword("admin");
dsc.setDbType(DbType.MYSQL);
mpg.setDataSource(dsc);
// 包配置
PackageConfig pc = new PackageConfig();
// pc.setModuleName(scanner("模块名"));
pc.setParent("com.xiecode.drug");
pc.setEntity("pojo");
pc.setMapper("mapper");
pc.setService("service");
pc.setController("controller");
// 自定义配置
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/mybatis/mapper/" + pc.getModuleName() + "/" + tableInfo.getEntityName() + "Mapper" + StringPool.DOT_XML;
}
});
/*
cfg.setFileCreate(new IFileCreate() {
@Override
public boolean isCreate(ConfigBuilder configBuilder, FileType fileType, String filePath) {
// 判断自定义文件夹是否需要创建
checkDir("调用默认方法创建的目录,自定义目录用");
if (fileType == FileType.MAPPER) {
// 已经生成 mapper 文件判断存在,不想重新生成返回 false
return !new File(filePath).exists();
}
// 允许生成模板文件
return true;
}
});
*/
cfg.setFileOutConfigList(focList);
mpg.setCfg(cfg);
mpg.setPackageInfo(pc);
// 如果模板引擎是 velocity
// 配置模板
TemplateConfig templateConfig = new TemplateConfig();
// 配置自定义输出模板
// 指定自定义模板路径,注意不要带上.ftl/.vm, 会根据使用的模板引擎自动识别
// templateConfig.setEntity("templates/entity2.java");
// templateConfig.setService();
// templateConfig.setController();
templateConfig.setXml(null);
mpg.setTemplate(templateConfig);
mpg.setPackageInfo(pc);
// 如果模板引擎是 velocity
// 策略配置
StrategyConfig strategy = new StrategyConfig();
strategy.setNaming(NamingStrategy.underline_to_camel);
strategy.setColumnNaming(NamingStrategy.underline_to_camel);
// strategy.setSuperEntityClass("你自己的父类实体,没有就不用设置!");
strategy.setEntityLombokModel(true);
strategy.setRestControllerStyle(true);
// 公共父类
// strategy.setSuperControllerClass("你自己的父类控制器,没有就不用设置!");
// 写于父类中的公共字段
// strategy.setSuperEntityColumns("id");
// strategy.setInclude(scanner("表名,多个英文逗号分割").split(","));
strategy.setInclude("sell_is_gone");
strategy.setControllerMappingHyphenStyle(true);
// strategy.setTablePrefix(pc.getModuleName() + "_");
mpg.setStrategy(strategy);
mpg.setTemplateEngine(new VelocityTemplateEngine());
mpg.execute();
}
use of com.baomidou.mybatisplus.generator.InjectionConfig in project chao-cloud by chaojunzi.
the class MybatisGeneratorConfig method InjectionConfig.
@Bean
public InjectionConfig InjectionConfig() {
// 自定义配置
InjectionConfig cfg = new InjectionConfig() {
@Override
public void initMap() {
}
};
// 自定义输出配置
List<FileOutConfig> focList = new ArrayList<>();
cfg.setFileOutConfigList(focList);
return cfg;
}
use of com.baomidou.mybatisplus.generator.InjectionConfig in project demo-parent by yindanqing925.
the class MysqlGenerator method main.
/**
* RUN THIS
*/
public static void main(String[] args) {
// 代码生成器
AutoGenerator mpg = new AutoGenerator();
// 全局配置
GlobalConfig gc = new GlobalConfig();
String projectPath = System.getProperty("user.dir") + "/mybatisplus-demo";
gc.setOutputDir(projectPath + "/src/main/java");
// TODO 设置用户名
gc.setAuthor("yindanqing");
gc.setOpen(false);
// service 命名方式
gc.setServiceName("%sService");
// service impl 命名方式
gc.setServiceImplName("%sServiceImpl");
// 自定义文件命名,注意 %s 会自动填充表实体属性!
gc.setMapperName("%sMapper");
gc.setXmlName("%sMapper");
gc.setFileOverride(true);
gc.setActiveRecord(true);
// XML 二级缓存
gc.setEnableCache(false);
// XML ResultMap
gc.setBaseResultMap(true);
// XML columList
gc.setBaseColumnList(false);
mpg.setGlobalConfig(gc);
// TODO 数据源配置
DataSourceConfig dsc = new DataSourceConfig();
dsc.setUrl("jdbc:mysql://cdb-1v2wt3os.bj.tencentcdb.com:10243/nh?useUnicode=true&characterEncoding=UTF8");
dsc.setDriverName("com.mysql.jdbc.Driver");
dsc.setUsername("user_dev");
dsc.setPassword("user_dev_nh");
mpg.setDataSource(dsc);
// TODO 包配置
PackageConfig pc = new PackageConfig();
// pc.setModuleName(scanner("模块名"));
pc.setParent("org.nh.mybatisplus.dict");
pc.setEntity("domain");
pc.setService("service");
pc.setServiceImpl("service.impl");
mpg.setPackageInfo(pc);
// 自定义需要填充的字段
List<TableFill> tableFillList = new ArrayList<>();
// 如 每张表都有一个创建时间、修改时间
// 而且这基本上就是通用的了,新增时,创建时间和修改时间同时修改
// 修改时,修改时间会修改,
// 虽然像Mysql数据库有自动更新几只,但像ORACLE的数据库就没有了,
// 使用公共字段填充功能,就可以实现,自动按场景更新了。
// 如下是配置
// TableFill createField = new TableFill("gmt_create", FieldFill.INSERT);
// TableFill modifiedField = new TableFill("gmt_modified", FieldFill.INSERT_UPDATE);
// tableFillList.add(createField);
// tableFillList.add(modifiedField);
// 自定义配置
InjectionConfig cfg = new InjectionConfig() {
@Override
public void initMap() {
// to do nothing
}
};
List<FileOutConfig> focList = new ArrayList<>();
focList.add(new FileOutConfig("/templates/mapper.xml.ftl") {
@Override
public String outputFile(TableInfo tableInfo) {
// 自定义输入文件名称
return projectPath + "/src/main/java/org/nh/mybatisplus/dict/mapper/" + tableInfo.getEntityName() + "Mapper" + ".xml";
}
});
cfg.setFileOutConfigList(focList);
mpg.setCfg(cfg);
mpg.setTemplate(new TemplateConfig().setXml(null));
// 策略配置
StrategyConfig strategy = new StrategyConfig();
strategy.setNaming(NamingStrategy.underline_to_camel);
strategy.setColumnNaming(NamingStrategy.underline_to_camel);
strategy.setEntityLombokModel(true);
// 设置逻辑删除键
strategy.setLogicDeleteFieldName("deleted");
// TODO 指定生成的bean的数据库表名
strategy.setInclude("transfer_dict");
// strategy.setSuperEntityColumns("id");
// 驼峰转连字符
strategy.setControllerMappingHyphenStyle(true);
mpg.setStrategy(strategy);
// 选择 freemarker 引擎需要指定如下加,注意 pom 依赖必须有!
mpg.setTemplateEngine(new FreemarkerTemplateEngine());
mpg.execute();
}
Aggregations