FreeMarker的使用步驟

2021-09-26 15:05:04 字數 1099 閱讀 4971

原始freemarker的用法:

configuration config = new configuration(configuration.getversion());

//這裡設定的是模版目錄

config.setdirectoryfortemplateloading(new file("模板位址"));

config.setdefaultencoding("utf-8");

//這裡是模版檔名

template template = config.gettemplate("模板檔名");

filewriter out = new filewriter(new file("f:\\temp\\hello.html"));

//todo ... 得到模板想要的資料,封裝到物件或乙個map集合中。

template.process(map/物件, out);

out.close();

有配置檔案的用法

配置檔案xx.properties:

pagedir=d:\\生成路徑
正文

//獲取配置檔案

configuration configuration = freemarkerconfig.getconfiguration();

//獲取模板

template template = configuration.gettemplate("item.ftl");

//todo ... 得到模板想要的資料,封裝到物件或乙個map集合中。

//使用這個輸出流,不會亂碼

writer out =new bufferedwriter(new outputstreamwriter(

new fileoutputstream(pagedir+goodsid+".html"), "utf-8"));

template.process(datamap, out);

out.close();

Freemarker使用筆記1 配置步驟

一 freemarker簡介 網頁靜態化技術和快取技術的共同點都是為了減輕資料庫的訪問壓力,但是具體的應用場景不同,快取比較適合小規模的資料,而網頁靜態化比較適合大規模且相對變化不太頻繁的資料。另外網頁靜態化還有利於seo。另外我們如果將網頁以純靜態化的形式展現,就可以使用nginx這樣的高效能的w...

FreeMarker 的使用方法

匯入jar包 freemarker.jar 測試類 public class testfreemarker 模板檔案 users 使用者名稱 documents ftl hello.ftl 2.1 模板語法 2.1.1 訪問map中的key 2.1.2 訪問pojo中的屬性 2.1.3 獲取集合中的...

Freemarker使用入門 servlet

freemarker是開源的模板框架。對於它的介紹網上已經很多了。詳情可參考主頁 4.在web inf目錄下建一資料夾templates,然後在這個資料夾裡面新建乙個模板檔案test.ftl 5.建乙個helloservlet protected void dopost httpservletreq...