FreeMarker 语法 include 引用模板
生活随笔
收集整理的這篇文章主要介紹了
FreeMarker 语法 include 引用模板
小編覺得挺不錯的,現(xiàn)在分享給大家,幫大家做個參考.
一、java 代碼
@Test public void testFreeMarker() throws Exception {//1、創(chuàng)建一個模板文件//2、創(chuàng)建一個Configuration對象Configuration configuration = new Configuration();//3、設(shè)置模板文件保存的目錄configuration.setDirectoryForTemplateLoading(new File("E:/workspaces/fw-item-web/src/main/webapp/WEB-INF/ftl"));//4、模板文件的編碼格式,一般就是utf-8configuration.setDefaultEncoding("utf-8");//5、加載一個模板文件,創(chuàng)建一個模板對象。Template template = configuration.getTemplate("student.ftl");//6、創(chuàng)建一個數(shù)據(jù)集。可以是pojo也可以是map。推薦使用mapMap data = new HashMap<>();data.put("studnet", "studnet.ftl");data.put("hello", "hello.ftl");//7、創(chuàng)建一個Writer對象,指定輸出文件的路徑及文件名。Writer out = new FileWriter(new File("E:/freemarker/student.html"));//8、生成靜態(tài)頁面 template.process(data, out);//9、關(guān)閉流 out.close(); }二、studnet.ftl
<html> <head><title>null</title> </head> <body>student.ftl 模板:<br>${studnet}<br><br>引用模板測試:<br>hello.ftl 模板:<br><#include "hello.ftl"></body> </html>三、hello.ftl
${hello}四、結(jié)果
?
轉(zhuǎn)載于:https://www.cnblogs.com/fangwu/p/8696443.html
總結(jié)
以上是生活随笔為你收集整理的FreeMarker 语法 include 引用模板的全部內(nèi)容,希望文章能夠幫你解決所遇到的問題。
- 上一篇: Yii 判断是不是post方式提交的数据
- 下一篇: Linux 下 zip unzip压缩与