freemarker helloworld

来源:互联网 发布:ubuntu cuda9.0 caffe 编辑:程序博客网 时间:2024/04/30 14:16
package com.wxl.app.freemarker;import java.io.File;import java.io.IOException;import java.io.StringWriter;import java.util.Map;import freemarker.template.Configuration;import freemarker.template.Template;import freemarker.template.TemplateException;public class SimpleTemplate {public String process(String path, Map<String, Object> map) throws IOException, TemplateException {Configuration cfg = new Configuration();cfg.setDirectoryForTemplateLoading(new File("E:/java/freemarker/freemarker-2.3.19/freemarker-2.3.19/examples/webapp1/WEB-INF/templates"));Template template = cfg.getTemplate(path);StringWriter sw = new StringWriter();template.process(map, sw);return sw.toString();}}