日韩av黄I国产麻豆传媒I国产91av视频在线观看I日韩一区二区三区在线看I美女国产在线I麻豆视频国产在线观看I成人黄色短片

歡迎訪問 生活随笔!

生活随笔

當(dāng)前位置: 首頁 >

FreeMarker 语法 include 引用模板

發(fā)布時(shí)間:2025/7/14 53 豆豆
生活随笔 收集整理的這篇文章主要介紹了 FreeMarker 语法 include 引用模板 小編覺得挺不錯(cuò)的,現(xiàn)在分享給大家,幫大家做個(gè)參考.

一、java 代碼

@Test public void testFreeMarker() throws Exception {//1、創(chuàng)建一個(gè)模板文件//2、創(chuàng)建一個(gè)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、加載一個(gè)模板文件,創(chuàng)建一個(gè)模板對象。Template template = configuration.getTemplate("student.ftl");//6、創(chuàng)建一個(gè)數(shù)據(jù)集。可以是pojo也可以是map。推薦使用mapMap data = new HashMap<>();data.put("studnet", "studnet.ftl");data.put("hello", "hello.ftl");//7、創(chuàng)建一個(gè)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)容,希望文章能夠幫你解決所遇到的問題。

如果覺得生活随笔網(wǎng)站內(nèi)容還不錯(cuò),歡迎將生活随笔推薦給好友。