use of com.baomidou.mybatisplus.generator.engine.AbstractTemplateEngine in project code-generator-maven-plugin by mengweijin.
the class FileOutput method outputFile.
public static void outputFile(TableInfo tableInfo, Map<String, Object> objectMap, ProjectInfo projectInfo, String outputDir) {
Parameters parameters = projectInfo.getParameters();
AbstractTemplateEngine templateEngine = TemplateEngineFactory.getTemplateEngine(parameters.getTemplateType());
String outputPackage = parameters.getOutputPackage();
List<File> templateFileList = FileUtil.loopFiles(parameters.getTemplateLocation(), file -> file.isFile() && file.getName().toLowerCase().endsWith(parameters.getTemplateType().getSuffix()));
if (CollectionUtil.isEmpty(templateFileList)) {
throw new RuntimeException("No template files found in location " + parameters.getTemplateLocation());
} else {
String message = "Found " + templateFileList.size() + " template files in location " + parameters.getTemplateLocation();
log.info(message);
}
try {
for (File templateFile : templateFileList) {
// 初始化输出文件的名称和路径
File outputFile = buildOutputFile(tableInfo, templateFile.getAbsolutePath(), outputDir, outputPackage);
FileUtil.mkParentDirs(outputFile);
// 使用模板引擎,渲染并输出文件
templateEngine.writer(objectMap, templateFile.getAbsolutePath(), outputFile);
}
} catch (Exception e) {
log.error("Template engine writer error!", e);
throw new RuntimeException(e);
}
}
Aggregations