package main;
import java.io.BufferedWriter;
import java.io.File;
import java.io.FileOutputStream;
import java.io.IOException;
import java.io.OutputStreamWriter;
import java.io.Writer;
import java.util.HashMap;
import java.util.Map;
import freemarker.template.Configuration;
import freemarker.template.Template;
import freemarker.template.TemplateException;
public class TestMain {
public static void main(String[] args) throws IOException, TemplateException {
// 制造数据
Map<String, String> map = new HashMap<String, String>();
map.put("mm", "展示列表tttt");
map.put("text", "freemaker展示fffff页面");
// 找到模板文件*.ftl
Configuration freemarker_cfg = new Configuration();
String ftlppath = "e:\\freemarker\\";
freemarker_cfg.setDirectoryForTemplateLoading(new File(ftlppath));
Template template = freemarker_cfg.getTemplate("product.ftl");
// 合并模板文件以及数据将其进行输出
Writer out = new BufferedWriter(new OutputStreamWriter(new FileOutputStream("e:\\freemarker\\myFreemarker.html"), "utf-8"));
//进行处理
template.process(map, out);
}
}
main程序的freemarker
最新推荐文章于 2021-03-20 08:47:25 发布