freemarker 基本指令
一:if指令:
condition>...
condition2>...
condition3>...
......
#if>
二:switch
value>
refValue1>...
refValue2>......
refValueN>...
...#switch>
三:list,break
sequence as item>
...
#list>
兩個特殊的迴圈變數:
item_index: 當前變數的索引值。
item_has_next: 是否存在下一個物件。
可以用指令離開loop迴圈。
四:include指令
filename>或者
filenameoptions>
filename: 表示式轉換為字串
options: encoding=encoding, parse=parse encoding: 表示式轉換為字串
parse: 表示式轉換為邏輯值,是否作為ftl檔案解析。
表示當前目錄下以及所有父目錄下的檔案。如果當前模版在/foo/bar/template.ftl ,那麼查詢footer.ftl的順序為:/foo/bar/footer.ftl
/foo/footer.ftl/footer.ftl這種方式講允許設計者將通用的模版放在父資料夾裡面。
也可以只指定部分路徑:
五:import指令path as hash>
六:noparse
...
#noparse>
七:compress
...
#compress>
八:escape,noescape
identifier as expression>
...
...#noescape>
...
#escape>
escape指令body區的ftl的interpolations都會被自動加上escape表示式。但是不會影響字串內的interpolations。而且也只會影響到body內出現的interpolations,比如不會影響到include的ftl的interpolations。
condition>...
condition2>...
condition3>...
......
#if>
二:switch
value>
refValue1>...
refValue2>......
refValueN>...
...#switch>
三:list,break
sequence as item>
...
#list>
兩個特殊的迴圈變數:
item_index: 當前變數的索引值。
item_has_next: 是否存在下一個物件。
可以用指令離開loop迴圈。
四:include指令
filename>或者
filenameoptions>
filename: 表示式轉換為字串
options: encoding=encoding, parse=parse encoding: 表示式轉換為字串
parse: 表示式轉換為邏輯值,是否作為ftl檔案解析。
表示當前目錄下以及所有父目錄下的檔案。如果當前模版在/foo/bar/template.ftl ,那麼查詢footer.ftl的順序為:/foo/bar/footer.ftl
/foo/footer.ftl/footer.ftl這種方式講允許設計者將通用的模版放在父資料夾裡面。
也可以只指定部分路徑:
五:import指令path as hash>
六:noparse
...
#noparse>
七:compress
...
#compress>
八:escape,noescape
identifier as expression>
...
...#noescape>
...
#escape>
escape指令body區的ftl的interpolations都會被自動加上escape表示式。但是不會影響字串內的interpolations。而且也只會影響到body內出現的interpolations,比如不會影響到include的ftl的interpolations。
First name: ${firstName}
Last name: ${lastName}
Maiden name: ${maidenName}#escape>
等同於:
First name: ${firstName?html}
Last name: ${lastName?html}
Maiden name: ${maidenName?html}
escape指令在解析模版時起作用,而不是執行時起作用。
escape指令還能巢狀使用,子繼承父的escape規則。
Customer Name: ${customerName}
Items to ship:
${itemCode1}
${itemCode2}
${itemCode3}
${itemCode4}
#escape>#escape>
等同於:Customer Name: ${customerName?html}
Items to ship:
${itemCodeToNameMap[itemCode1]?html}
${itemCodeToNameMap[itemCode2]?html}
${itemCodeToNameMap[itemCode3]?html}
${itemCodeToNameMap[itemCode4]?html}
九:assign指令
name=value>
or
name1=value1name2=value2... nameN=valueN>orname>
capture this
#global>
十一:local指令
name=value>
or
name1=value1name2=value2... nameN=valueN>orname>
capture this
#local>只能用於macro的定義body中。
十二:setting指令:
name=value>
name的取值範圍:
local:number_format:
boolean_format:預設值為"true,false"
date_format, time_format, datetime_format
time_zone:url_escaping_charset
classic_compatible
十三:使用者自定義指令
nameparam1param2... paramN>
...
loopvar1, loopvar2, ..., loopvarN>
...
...
#macro>
十五:function, return
nameparam1param2... paramN>
... returnValue>
...
#function>
#function>
${avg(10, 20)}
十六:flush
十七:stop
or
reason>取消處理模版。
十八:ftl指令
param1=value1param2=value2...paramN=valueN>
ftl指令必須放在ftl檔案的最上面。
引數範圍:
encoding:
strip_whitespace
strip_text
strict_syntax
十九:t, lt, rt
二十:attempt, recover
attempt block
recover block
#attempt>
Optional content: ${thisMayFails}
Ops! The optional content is not available.
#attempt>
[@more@]
Last name: ${lastName?html}
Maiden name: ${maidenName?html}
escape指令在解析模版時起作用,而不是執行時起作用。
escape指令還能巢狀使用,子繼承父的escape規則。
Customer Name: ${customerName}
Items to ship:
${itemCode1}
${itemCode2}
${itemCode3}
${itemCode4}
#escape>#escape>
等同於:Customer Name: ${customerName?html}
Items to ship:
${itemCodeToNameMap[itemCode1]?html}
${itemCodeToNameMap[itemCode2]?html}
${itemCodeToNameMap[itemCode3]?html}
${itemCodeToNameMap[itemCode4]?html}
九:assign指令
name=value> or name1=value1name2=value2... nameN=valueN> or same as above... in namespacehash> or name> capture this #assign> or name in namespacehash> capture this #assign>十:global指令
建立或者替換一個已經存在的變數,只能作用於頂層變數。 不好的做法:Hello ${user}!#assign>
更改為:
name=value>
or
name1=value1name2=value2... nameN=valueN>orname>
capture this
#global>
十一:local指令
name=value>
or
name1=value1name2=value2... nameN=valueN>orname>
capture this
#local>只能用於macro的定義body中。
十二:setting指令:
name=value>
name的取值範圍:
local:number_format:
boolean_format:預設值為"true,false"
date_format, time_format, datetime_format
time_zone:url_escaping_charset
classic_compatible
十三:使用者自定義指令
macro_or_transfparam1=val1param2=val2...paramN=valN/>macro_or_transfparam1=val1param2=val2...paramN=valN ; lv1, lv2, ..., lvN/>macro_or_transf...> ... @macro_or_transf>十四:macro,nested,return
macro_or_transf...> ... @>macro_or_transfval1, val2, ..., valN/>
nameparam1param2... paramN>
...
loopvar1, loopvar2, ..., loopvarN>
...
...
#macro>
十五:function, return
nameparam1param2... paramN>
... returnValue>
...
#function>
#function>
${avg(10, 20)}
十六:flush
十七:stop
or
reason>取消處理模版。
十八:ftl指令
param1=value1param2=value2...paramN=valueN>
ftl指令必須放在ftl檔案的最上面。
引數範圍:
encoding:
strip_whitespace
strip_text
strict_syntax
十九:t, lt, rt
二十:attempt, recover
attempt block
recover block
#attempt>
Optional content: ${thisMayFails}
Ops! The optional content is not available.
#attempt>
來自 “ ITPUB部落格 ” ,連結:http://blog.itpub.net/750220/viewspace-913997/,如需轉載,請註明出處,否則將追究法律責任。
相關文章
- linux基本指令Linux
- vue基本指令Vue
- FreeMarker
- Freemarker的迴圈通過assign指令引入計數變數變數
- Linux基本操作指令Linux
- vue基本指令與腳手架基本配置Vue
- FreeMarker入門
- itextpdf freemarker渲染
- freemarker初次使用
- FreeMarker模板引擎
- Linux下的基本指令(一)Linux
- shell指令碼——基本運算子指令碼
- bat指令碼的基本操作BAT指令碼
- node-red的基本指令
- 初級Vue以及基本指令Vue
- Django的下載和基本指令Django
- shell-----構建基本指令碼指令碼
- freemarker 生成前端檔案前端
- Java模板引擎之FreeMarkerJava
- 關於FreeMarker模板注入
- freemarker 生成 Java 程式碼Java
- springboot模版thymeleaf+freemarkerSpring Boot
- 【MATLAB】基本繪圖函式(涵蓋所有基本繪圖指令)Matlab繪圖函式
- FreeMarker 之快速入門Demo
- java Freemarker 模版引擎工具類Java
- Spring Boot 整合 FreeMarker 例項Spring Boot
- linux-MySQL基本指令-增刪改查LinuxMySql
- IOT2050基本使用和指令集
- PSQL基本使用(定製維護指令碼)SQL指令碼
- shell指令碼基本概念和命令小結指令碼
- spring原始碼分析之freemarker整合Spring原始碼
- Spring Boot (三)模板引擎FreeMarker整合Spring Boot
- RD基本功——Vi基礎與最常用指令
- 【SCRIPT】Oracle資料庫基本資訊收集指令碼Oracle資料庫指令碼
- 從官方文件去學習之FreeMarker
- Java整合FreeMarker匯出Pdf檔案Java
- Is it going on-------------Docker容器的安裝以及基本的操作指令GoDocker
- day67:Vue:es6基本語法&vue.js基本使用&vue指令系統Vue.js
- Shell指令碼基本編輯規範及變數(詳細)指令碼變數