FreeMarker HelloWord列子
来源:互联网 发布:mysql employees 导入 编辑:程序博客网 时间:2024/06/05 00:00
工程目录结构:
源码列子:
package org.ftl.test;import Java.io.File;import java.io.FileWriter;import java.io.IOException;import java.io.PrintWriter;import java.util.HashMap;import java.util.Map;import org.junit.Test;import freemarker.core.ParseException;import freemarker.template.Configuration;import freemarker.template.MalformedTemplateNameException;import freemarker.template.Template;import freemarker.template.TemplateException;import freemarker.template.TemplateNotFoundException;import freemarker.template.Version;public class TestFreemarker { @Test public void testHelloToHtml() throws TemplateNotFoundException, MalformedTemplateNameException, ParseException, IOException, TemplateException{ //1:创建configuration Configuration cfg= new Configuration(new Version("2.3.23")); //2:设置configuration中模版加载的路径 //基于classpath加载路径,并且所有模版都放在/ftl/templates中 cfg.setClassForTemplateLoading(TestFreemarker.class, "/ftl/templates"); //3:获取模版文件 Template template=cfg.getTemplate("hello.ftl"); //4:创建数据,一般使用map Map<String, String> root= new HashMap<String, String>(); root.put("username", "jacky"); //5:通过数据与模版的结合进行输出 template.process(root, new FileWriter(new File("d:/test/freemarker/hello.html"))); } //@Test public void testHello() throws TemplateNotFoundException, MalformedTemplateNameException, ParseException, IOException, TemplateException{ //1:创建configuration Configuration cfg= new Configuration(new Version("2.3.23")); //2:设置configuration中模版加载的路径 //基于classpath加载路径,并且所有模版都放在/ftl/templates中 cfg.setClassForTemplateLoading(TestFreemarker.class, "/ftl/templates"); //3:获取模版文件 Template template=cfg.getTemplate("hello.ftl"); //4:创建数据,一般使用map Map<String, String> root= new HashMap<String, String>(); root.put("username", "刘德华"); //5:通过数据与模版的结合进行输出 template.process(root, new PrintWriter(System.out)); }}
0 0
- FreeMarker HelloWord列子
- FreeMarker HelloWord列子
- freemarker入门笔记之一:永恒的helloword
- spring与freemarker集成,顺带spring mvc的helloword部署
- HelloWord
- HelloWord
- helloword
- Helloword
- HelloWord!
- helloword
- HelloWord!!!
- helloword
- helloword
- HelloWord
- HelloWord
- HelloWord
- helloword
- 正则列子
- 如何判断UIViewController是使用pop,dismiss返回到上级视图控制器
- java读取properties文件
- 【STM32】STM32之timer3产生PWM
- Logger 漂亮的日志输出log
- ButterKnife8.1.0(高版本)之后,使用插件失效原因分析
- FreeMarker HelloWord列子
- 微信小程序登录密码MD5加密
- Chrome扩展入门基础
- left jion时,on和where
- 用php获取设备信息
- Kafka环境搭建及与Spring的整合测试
- Win10自动更新,导致的Sql Server连接失败
- 最小生成树-Prim算法和Kruskal算法
- 用WIN7装oracle10g的步骤