use of com.spawpaw.mybatis.generator.gui.entity.Table in project mybatis-generator-gui-extension by spawpaw.
the class SCVXGeneratorPlugin method contextGenerateAdditionalJavaFiles.
@Override
public List<GeneratedJavaFile> contextGenerateAdditionalJavaFiles(IntrospectedTable introspectedTable) {
log.info(">>>> generating extra files...");
// : 2018/3/22 将 introspectedTable 转化为对象
Map<String, String> map = new HashMap<>();
for (Object o : properties.keySet()) {
map.put(o.toString(), properties.getProperty(o.toString()));
}
Table table = new Table(context, introspectedTable, map);
// : 2018/3/22 初始化context
VelocityContext templateContext = new VelocityContext();
templateContext.put("table", table);
templateContext.put("projectDir.ss", projectDir);
// 输出测试数据
String content = renderTemplateAsString("test.vm", templateContext);
log.info("hierarchical table structure: {}", content);
// : 2018/3/22 保存到指定目录
List<TemplateConfig> configs = new Yaml().loadAs(Thread.currentThread().getContextClassLoader().getResourceAsStream("config.yml"), ConfigWrapper.class).getTemplateConfig();
for (TemplateConfig config : configs) {
String template = config.getTemplate();
String destDir = config.getDestDir().replaceAll("\\.", "/");
String destPackage = config.getDestPackage();
String destFileName = config.getDestFileName();
String absPath = (projectDir == null || projectDir.isEmpty() ? "" : projectDir) + destDir + "/" + destPackage.replace(".", "/") + "/" + destFileName;
absPath = absPath.replace("//", "/");
absPath = absPath.replace("${entityName}", table.getEntityName());
absPath = absPath.replace("${basePackage}", basePackage.replace(".", "/"));
log.info("generate file `{}` from template `{}`", absPath, template);
content = renderTemplateAsString(config.getTemplate(), templateContext);
// 写入文件
try {
FileUtil.writeStringToFile(absPath, content);
} catch (IOException e) {
log.error(e.getMessage());
}
log.info("content: {}", content);
}
log.info("<<< generated extra files.");
return null;
}
Aggregations