public static boolean createFile(String ftl, Map<String, Object> data, String targetFile) {
try {
// 创建Template对象
Configuration cfg = new Configuration(Configuration.VERSION_2_3_0);
cfg.setDefaultEncoding("UTF-8");
//获取模板
Template template = cfg.getTemplate(ftl);
Writer out = new BufferedWriter(new OutputStreamWriter(new FileOutputStream
(targetFile), "UTF-8"));
template.process(data, out);
out.flush();
out.close();
} catch (IOException e) {
e.printStackTrace();
return false;
} catch (TemplateException e) {
e.printStackTrace();
return false;
}
return true;
}
freemarker 生成代码
最新推荐文章于 2023-12-13 22:44:05 发布