use of com.baomidou.mybatisplus.generator.config.po.TableInfo in project java-apply by javachengwc.
the class AbstractGeneratorConfig method doMpGeneration.
public void doMpGeneration() {
init();
AutoGenerator autoGenerator = new AutoGenerator();
autoGenerator.setGlobalConfig(globalConfig);
autoGenerator.setDataSource(dataSourceConfig);
autoGenerator.setStrategy(strategyConfig);
autoGenerator.setPackageInfo(packageConfig);
autoGenerator.execute();
destory();
// 获取table信息,用于guns代码生成
List<TableInfo> tableInfoList = autoGenerator.getConfig().getTableInfoList();
if (tableInfoList != null && tableInfoList.size() > 0) {
this.tableInfo = tableInfoList.get(0);
}
}
use of com.baomidou.mybatisplus.generator.config.po.TableInfo in project dynamic_dataSource by tianliuzhen.
the class CodeGenerator method main.
public static void main(String[] args) {
String pathStr = "/mybatis-plus";
// 代码生成器
AutoGenerator mpg = new AutoGenerator();
// 全局配置
GlobalConfig gc = new GlobalConfig();
// 项目的相对路径
String projectPath = System.getProperty("user.dir") + pathStr;
System.out.println("项目的相对路径" + projectPath);
gc.setOutputDir(projectPath + "/src/main/java");
gc.setAuthor("Mr.tian");
gc.setOpen(false);
// gc.setSwagger2(true); //实体属性 Swagger2 注解
mpg.setGlobalConfig(gc);
// 数据源配置
DataSourceConfig dsc = new DataSourceConfig();
dsc.setUrl("jdbc:mysql://47.98.253.2:3306/master?useUnicode=true&useSSL=false&characterEncoding=utf8");
// 指定数据库
dsc.setSchemaName("test1");
dsc.setDriverName("com.mysql.jdbc.Driver");
dsc.setUsername("root");
dsc.setPassword("Tlz19970905");
mpg.setDataSource(dsc);
// 包配置
PackageConfig pc = new PackageConfig();
// TODO: 会新加一层路径
// pc.setModuleName(scanner("模块名"));
pc.setParent("com.aaa.mybatisplus");
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";
// 自定义输出配置 xml 配置文件
List<FileOutConfig> focList = new ArrayList<>();
// 自定义配置会被优先输出
// TODO: 生成 xml 文件
focList.add(new FileOutConfig(templatePath) {
@Override
public String outputFile(TableInfo tableInfo) {
// 自定义输出文件名 , 如果你 Entity 设置了前后缀、此处注意 xml 的名称会跟着发生变化!!
return // + pc.getModuleName()
projectPath + "/src/main/resources/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();
// 这里会在 mapper 目录下默认生成 xml 目录及文件
templateConfig.setXml(null);
mpg.setTemplate(templateConfig);
// 策略配置
StrategyConfig strategy = new StrategyConfig();
// 设置字段和表名的是否把下划线完成驼峰命名规则
strategy.setNaming(NamingStrategy.underline_to_camel);
strategy.setColumnNaming(NamingStrategy.underline_to_camel);
// 设置生成的实体类继承的父类
strategy.setSuperEntityClass("com.aaa.mybatisplus.common.BaseEntity");
strategy.setEntityLombokModel(true);
strategy.setRestControllerStyle(true);
// 公共父类
strategy.setSuperControllerClass("com.aaa.mybatisplus.common.BaseController");
// 写于父类中的公共字段
strategy.setSuperEntityColumns("id");
// TODO:要设置生成哪些表 如果不设置就是生成所有的表
// 2019/12/21
strategy.setInclude(scanner("表名,多个英文逗号分割").split(","));
strategy.setControllerMappingHyphenStyle(true);
strategy.setTablePrefix(pc.getModuleName() + "_");
mpg.setStrategy(strategy);
mpg.setTemplateEngine(new FreemarkerTemplateEngine());
mpg.execute();
}
use of com.baomidou.mybatisplus.generator.config.po.TableInfo in project c4p by xseuen.
the class CodeGenerator method codeGenerator.
/**
* 代码生成
*
* @see OutputFile
*/
@Test
public void codeGenerator() {
String projectPath = System.getProperty("user.dir");
String javaPath = projectPackage.replaceAll("\\.", "/");
// 设置自定义路径
Map<OutputFile, String> pathInfo = new HashMap<>();
pathInfo.put(OutputFile.mapperXml, projectPath + "/src/main/resources/mybatis/mapper/");
pathInfo.put(OutputFile.entity, projectPath + "/src/main/java/" + javaPath + "/entity/");
pathInfo.put(OutputFile.controller, projectPath + "/src/main/java/" + javaPath + "/controller/");
pathInfo.put(OutputFile.service, projectPath + "/src/main/java/" + javaPath + "/service/");
pathInfo.put(OutputFile.serviceImpl, projectPath + "/src/main/java/" + javaPath + "/service/impl/");
pathInfo.put(OutputFile.mapper, projectPath + "/src/main/java/" + javaPath + "/mapper/");
pathInfo.put(OutputFile.other, projectPath + "/src/main/java/" + javaPath + "/dto/");
AutoGenerator generator = new AutoGenerator(DATA_SOURCE_CONFIG);
generator.strategy(strategyConfig().entityBuilder().enableLombok().enableChainModel().idType(IdType.ASSIGN_ID).logicDeleteColumnName("is_deleted").addTableFills(// 基于数据库字段填充
new Column("gmt_created", FieldFill.INSERT)).addTableFills(new Column("gmt_modified", FieldFill.INSERT_UPDATE)).controllerBuilder().enableRestStyle().build());
generator.packageInfo(packageConfig().pathInfo(pathInfo).build());
generator.global(globalConfig().outputDir(projectPath + "/src/main/java").enableSwagger().disableOpenDir().build());
generator.injection(injectionConfig().build());
generator.execute(new FreemarkerTemplateEngine() {
@Override
protected void outputCustomFile(@NotNull Map<String, String> customFile, @NotNull TableInfo tableInfo, @NotNull Map<String, Object> objectMap) {
String entityName = tableInfo.getEntityName();
String otherPath = getPathInfo(OutputFile.other);
customFile.forEach((key, value) -> {
String fileName = String.format((otherPath + File.separator + "%s"), entityName + key);
outputFile(new File(fileName), objectMap, value);
});
}
});
}
use of com.baomidou.mybatisplus.generator.config.po.TableInfo in project matecloud by matevip.
the class SysCodeController method tableList.
/**
* 数据库表信息
* @param dataSourceId 数据源Id
* @return Result
*/
@PreAuth
@Log(value = "数据库表信息", exception = "数据库表信息请求异常")
@ApiOperation(value = "数据库表信息", notes = "数据库表信息")
@PostMapping("/table-list")
public Result<List<TableInfo>> tableList(@RequestParam String dataSourceId) {
SysDataSource sysDataSource = sysDataSourceService.getById(dataSourceId);
GlobalConfig gc = new GlobalConfig();
DataSourceConfig dsc = new DataSourceConfig();
dsc.setDbType(DbType.getDbType(sysDataSource.getDbType()));
dsc.setDriverName(sysDataSource.getDriverClass());
dsc.setUrl(sysDataSource.getUrl());
dsc.setUsername(sysDataSource.getUsername());
dsc.setPassword(sysDataSource.getPassword());
StrategyConfig strategyConfig = new StrategyConfig();
TemplateConfig templateConfig = new TemplateConfig();
ConfigBuilder config = new ConfigBuilder(new PackageConfig(), dsc, strategyConfig, templateConfig, gc);
List<TableInfo> list = config.getTableInfoList();
return Result.data(list);
}
use of com.baomidou.mybatisplus.generator.config.po.TableInfo in project waynboot-mall by wayn111.
the class Gen method main.
public static void main(String[] args) {
// 代码生成器
AutoGenerator mpg = new AutoGenerator();
// 全局配置
GlobalConfig gc = new GlobalConfig();
String projectPath = System.getProperty("user.dir");
gc.setOutputDir(projectPath + "/waynboot-common/src/main/java");
gc.setAuthor("wayn");
gc.setBaseColumnList(true);
gc.setBaseResultMap(true);
gc.setOpen(false);
// gc.setSwagger2(true); 实体属性 Swagger2 注解
mpg.setGlobalConfig(gc);
// 数据源配置
DataSourceConfig dsc = new DataSourceConfig();
dsc.setUrl("jdbc:mysql://192.168.31.49:3306/wayn_shop?useUnicode=true&characterEncoding=utf8&zeroDateTimeBehavior=convertToNull&useSSL=true&serverTimezone=GMT%2B8");
// dsc.setSchemaName("public");
dsc.setDriverName("com.mysql.cj.jdbc.Driver");
dsc.setUsername("root");
dsc.setPassword("admin123");
mpg.setDataSource(dsc);
// 包配置
PackageConfig pc = new PackageConfig();
pc.setService("service.tool");
pc.setServiceImpl("service.tool.impl");
pc.setMapper("mapper.tool");
pc.setEntity("domain.tool");
pc.setModuleName("");
pc.setParent("com.wayn.common.core");
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 + "/waynboot-common/src/main/resources/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);
// 配置模板
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("你自己的父类实体,没有就不用设置!");
strategy.setEntityLombokModel(true);
strategy.setRestControllerStyle(true);
// 公共父类
strategy.setSuperControllerClass("com.wayn.common.base.BaseController");
// 写于父类中的公共字段
strategy.setSuperEntityColumns("id");
strategy.setInclude(scanner("表名,多个英文逗号分割").split(","));
strategy.setControllerMappingHyphenStyle(true);
strategy.setTablePrefix(pc.getModuleName() + "_");
mpg.setStrategy(strategy);
mpg.setTemplateEngine(new FreemarkerTemplateEngine());
mpg.execute();
}
Aggregations