main
黄海 9 months ago
parent cf7fec8607
commit ae3f4a2767

@ -454,20 +454,23 @@ public class GenerateCodeWithFreeMaker {
dataModel.put("parameters", parameters);
dataModel.put("key", key);
dataModel.put("key_type", key_type);
// 创建一个 Configuration 实例
Configuration cfg = new Configuration(new Version(2, 3, 33));
//调用FreeMarker模板引擎
Configuration cfg = new Configuration(new Version(2, 3, 33));// 创建一个 Configuration 实例
// 设置模板目录
String path = System.getProperty("user.dir") + "/dsUtils/src/main/resources";
String codePath = System.getProperty("user.dir") + "/dsUtils/src/main/java/com/dsideal/Code";
cfg.setDirectoryForTemplateLoading(new File(path));
// 设置字符编码
cfg.setDefaultEncoding("UTF-8");
//1、生成Controller层代码
// 加载模板
Template template = cfg.getTemplate("Controller.ftl");
// 渲染模板到文件
Writer out = new FileWriter(codePath +"/"+ table + "_Controller.txt", StandardCharsets.UTF_8);
template.process(dataModel, out);
out.close();
System.out.println("生成Controller层代码完成");
}
}

Loading…
Cancel
Save