use of com.baomidou.mybatisplus.generator.config.po.TableInfo in project springbootquickstart by Pace2Car.
the class CodeGenerator method generateByTables.
public void generateByTables(String moduleName, String... tableNames) {
// 全局配置
GlobalConfig config = new GlobalConfig();
config.setActiveRecord(false).setAuthor(AUTHOR).setOutputDir(OUTPUT_FILE).setFileOverride(false).setOpen(false).setServiceName("%sService");
// 数据源配置
DataSourceConfig dataSourceConfig = new DataSourceConfig();
dataSourceConfig.setDbType(DbType.MYSQL).setUrl(DB_URL).setUsername(USER_NAME).setPassword(PASSWORD).setDriverName(DRIVER);
// 策略配置
StrategyConfig strategyConfig = new StrategyConfig();
strategyConfig.setEntityLombokModel(true).setCapitalMode(true).setNaming(NamingStrategy.underline_to_camel).setColumnNaming(NamingStrategy.underline_to_camel).setInclude(tableNames);
// 自定义配置
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) {
// 自定义输出文件名
return PROJECT_PATH + "/src/main/resources/mapper/" + (moduleName == null ? "" : moduleName) + "/" + tableInfo.getEntityName() + "Mapper" + ".xml";
}
});
cfg.setFileOutConfigList(focList);
// 配置模板
TemplateConfig templateConfig = new TemplateConfig();
templateConfig.setXml(null);
new AutoGenerator().setGlobalConfig(config).setDataSource(dataSourceConfig).setStrategy(strategyConfig).setCfg(cfg).setTemplate(templateConfig).setTemplateEngine(new FreemarkerTemplateEngine()).setPackageInfo(// 包配置
new PackageConfig().setModuleName(moduleName).setParent(PACKAGE).setController("controller").setEntity("entity")).execute();
}
use of com.baomidou.mybatisplus.generator.config.po.TableInfo in project ddf-common by dongfangding.
the class CodeGenerator method generate.
public static void generate() {
// 代码生成器
AutoGenerator mpg = new AutoGenerator();
// 全局配置
GlobalConfig gc = new GlobalConfig();
String projectPath = System.getProperty("user.dir") + "/ddf-common-mybatis-generator";
gc.setOutputDir(projectPath + "/src/main/java");
gc.setAuthor("mybatis-plus-generator");
gc.setFileOverride(true);
gc.setActiveRecord(false);
gc.setBaseResultMap(true);
gc.setBaseColumnList(true);
gc.setEnableCache(false);
gc.setOpen(false);
// gc.setSwagger2(true); 实体属性 Swagger2 注解
mpg.setGlobalConfig(gc);
// 数据源配置
DataSourceConfig dsc = new DataSourceConfig();
dsc.setUrl("jdbc:mysql://localhost:3306/better-together?useUnicode=true&characterEncoding=UTF8&useSSL=false&serverTimezone=GMT%2B8&zeroDateTimeBehavior=convertToNull&allowMultiQueries=true&autoReconnect=true&failOverReadOnly=false&maxReconnects=10&tinyInt1isBit=false");
dsc.setDriverName("com.mysql.cj.jdbc.Driver");
dsc.setUsername("root");
dsc.setPassword("123");
dsc.setTypeConvert(new MySqlTypeConvertCustom());
mpg.setDataSource(dsc);
// 包配置
PackageConfig pc = new PackageConfig();
// pc.setModuleName(scanner("模块名"));
pc.setParent("com.ddf.better.together");
pc.setEntity("model.entity");
/* pc.setService("com.ddf.boot.service");
pc.setServiceImpl("com.ddf.boot.service.impl");
pc.setController("com.ddf.boot.controller");
pc.setMapper("com.ddf.boot.mapper");*/
pc.setXml(null);
mpg.setPackageInfo(pc);
// 自定义配置
InjectionConfig cfg = new InjectionConfig() {
@Override
public void initMap() {
// to do nothing
}
};
// 如果模板引擎是 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;
}
});
/* // 自定义vo
focList.add(new FileOutConfig("myTemplates/vo.java.vm") {
@Override
public String outputFile(TableInfo tableInfo) {
return gc.getOutputDir() + "/com/code/generator/domain/vo/"
+ tableInfo.getEntityName()+"Vo" + StringPool.DOT_JAVA;
}
});*/
// 应用自定义文件输出
cfg.setFileOutConfigList(focList);
mpg.setCfg(cfg);
// 配置模板
TemplateConfig templateConfig = new TemplateConfig();
templateConfig.setXml(null);
mpg.setTemplate(templateConfig);
mpg.setTemplateEngine(new VelocityTemplateEngine());
// 策略配置
StrategyConfig strategy = new StrategyConfig();
// 过滤表名前缀
strategy.setTablePrefix("");
// 驼峰命名
strategy.setNaming(NamingStrategy.underline_to_camel);
strategy.setColumnNaming(NamingStrategy.underline_to_camel);
// 设置父类,如果存在的话
// strategy.setSuperEntityClass("com.ddf.boot.common.core.model.BaseDomain");
strategy.setEntityLombokModel(true);
strategy.setRestControllerStyle(true);
// 写于父类中的公共字段
// strategy.setSuperEntityColumns("id", "create_by", "create_time", "modify_by", "modify_time", "is_del", "version");
// 其它带父类的
// strategy.setSuperServiceClass("");
strategy.setInclude(scanner("表名,多个英文逗号分割").split(","));
strategy.setTablePrefix(pc.getModuleName() + "_");
mpg.setStrategy(strategy);
mpg.execute();
}
use of com.baomidou.mybatisplus.generator.config.po.TableInfo in project matecloud by matevip.
the class ManualGenerator method main.
public static void main(String[] args) {
// 代码生成器
AutoGenerator mpg = new AutoGenerator();
// 全局配置
GlobalConfig gc = new GlobalConfig();
// String projectPath = System.getProperty("user.dir");
// 生成路径改为从控制台输入
String projectPath = scanner("生成路径");
gc.setOutputDir(projectPath + "/src/main/java");
gc.setFileOverride(true);
// ActiveRecord特性
gc.setActiveRecord(false);
// XML ResultMap
gc.setBaseResultMap(true);
// XML columList
gc.setBaseColumnList(true);
gc.setEnableCache(false);
// 自动打开输出目录
gc.setOpen(false);
gc.setAuthor("pangu");
gc.setSwagger2(true);
// 主键策略
gc.setIdType(IdType.AUTO);
// 自定义文件命名,注意 %s 会自动填充表实体属性!
gc.setServiceName("I%sService");
gc.setServiceImplName("%sServiceImpl");
gc.setMapperName("%sMapper");
gc.setXmlName("%sMapper");
mpg.setGlobalConfig(gc);
// 数据源配置
DataSourceConfig dsc = new DataSourceConfig();
dsc.setUrl("jdbc:mysql://localhost:3306/matex?useUnicode=true&useSSL=false&characterEncoding=utf8");
// dsc.setSchemaName("public");
dsc.setDriverName("com.mysql.cj.jdbc.Driver");
dsc.setUsername("root");
dsc.setPassword("123456");
mpg.setDataSource(dsc);
// 包配置
PackageConfig pc = new PackageConfig();
// pc.setModuleName(scanner("模块名"));
// 此处设置包名,需要自定义
pc.setParent(scanner("包名"));
mpg.setPackageInfo(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 gc.getOutputDir() + StringPool.SLASH + pc.getParent().replace(".", StringPool.SLASH) + "/mapper/" + tableInfo.getEntityName() + "Mapper" + StringPool.DOT_XML;
}
});
/*
cfg.setFileCreate(new IFileCreate() {
@Override
public boolean isCreate(ConfigBuilder configBuilder, FileType fileType, String filePath) {
// 判断自定义文件夹是否需要创建
checkDir("调用默认方法创建的目录");
return false;
}
});
*/
cfg.setFileOutConfigList(focList);
mpg.setCfg(cfg);
// 配置模板
TemplateConfig templateConfig = new TemplateConfig();
// 配置自定义输出模板
// 指定自定义模板路径,注意不要带上.ftl/.vm, 会根据使用的模板引擎自动识别
// templateConfig.setEntity("templates/entity2.java");
// templateConfig.setService();
// templateConfig.setController();
templateConfig.setXml(null);
mpg.setTemplate(templateConfig);
// 策略配置
StrategyConfig strategy = new StrategyConfig();
strategy.setNaming(NamingStrategy.underline_to_camel);
strategy.setColumnNaming(NamingStrategy.underline_to_camel);
strategy.setSuperEntityClass("vip.mate.core.database.entity.BaseEntity");
strategy.setEntityLombokModel(true);
strategy.setRestControllerStyle(true);
// 公共父类
strategy.setSuperControllerClass("vip.mate.core.web.controller.BaseController");
// 写于父类中的公共字段
strategy.setSuperEntityColumns("id");
strategy.setInclude(scanner("表名,多个英文逗号分割").split(","));
strategy.setControllerMappingHyphenStyle(true);
strategy.setTablePrefix(scanner("表前缀"));
// strategy.setTablePrefix(pc.getModuleName() + "_");
mpg.setStrategy(strategy);
mpg.setTemplateEngine(new VelocityTemplateEngine());
mpg.execute();
}
use of com.baomidou.mybatisplus.generator.config.po.TableInfo in project newBlog by 1537069101.
the class CodeGenerator method main.
public static void main(String[] args) {
System.out.println("----------------------------============-----------------------------");
// 代码生成器
AutoGenerator mpg = new AutoGenerator();
// 全局配置
GlobalConfig gc = new GlobalConfig();
String projectPath = System.getProperty("user.dir");
gc.setOutputDir(projectPath + "/src/main/java");
// gc.setOutputDir("D:\\test");
gc.setAuthor("");
gc.setOpen(false);
// gc.setSwagger2(true); 实体属性 Swagger2 注解
gc.setServiceName("%sService");
mpg.setGlobalConfig(gc);
// 数据源配置
DataSourceConfig dsc = new DataSourceConfig();
dsc.setUrl("jdbc:mysql://119.91.255.208:3306/wiki?useUnicode=true&useSSL=false&characterEncoding=utf8&serverTimezone=Asia/Shanghai");
// dsc.setSchemaName("public");
dsc.setDriverName("com.mysql.cj.jdbc.Driver");
dsc.setUsername("root");
dsc.setPassword("Password");
mpg.setDataSource(dsc);
// 包配置
PackageConfig pc = new PackageConfig();
pc.setModuleName(null);
pc.setParent("cn.zzzyuan");
mpg.setPackageInfo(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/" + "/" + tableInfo.getEntityName() + "Mapper" + StringPool.DOT_XML;
}
});
cfg.setFileOutConfigList(focList);
mpg.setCfg(cfg);
// 配置模板
TemplateConfig templateConfig = new TemplateConfig();
templateConfig.setXml(null);
mpg.setTemplate(templateConfig);
// 策略配置
StrategyConfig strategy = new StrategyConfig();
strategy.setNaming(NamingStrategy.underline_to_camel);
strategy.setColumnNaming(NamingStrategy.underline_to_camel);
strategy.setEntityLombokModel(true);
strategy.setRestControllerStyle(true);
strategy.setInclude(scanner("表名,多个英文逗号分割").split(","));
strategy.setControllerMappingHyphenStyle(true);
strategy.setTablePrefix("t_");
mpg.setStrategy(strategy);
mpg.setTemplateEngine(new FreemarkerTemplateEngine());
mpg.execute();
}
use of com.baomidou.mybatisplus.generator.config.po.TableInfo 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;
}
Aggregations