freemaker学习笔记--其它内置方法

xiaoxiao2026-08-25  6

一:数字型<#assign answer=42/>${answer}${answer?string}  <#-- the same as ${answer} -->${answer?string.number}${answer?string.currency}${answer?string.percent}<#setting number_format="0.###E0"/>${12345?string("0.####E0")}  ${answer?string("number")} 等同于:${answer?string.number}.二:日期型:预定义格式包括:short ,middle和long。

${openingTime?string.short} ${openingTime?string.medium} ${openingTime?string.long}

组合使用:${lastUpdated?string.short_long}${lastUpdated?string("yyyy-MM-dd HH:mm:ss zzzz")}[iocblog.net 来源]三:逻辑型foo?stringfoo?string("yes", "no")四:序列的内置方法:firstlastseq_contains${x?seq_contains("blue")?string("yes", "no")}seq_index_ofseq_last_index_ofreversesizesortsort_by多层次的hash排序<#assign members = [    {"name": {"first": "Joe", "last": "Smith"}, "age": 40},    {"name": {"first": "Fred", "last": "Crooger"}, "age": 35},    {"name": {"first": "Amanda", "last": "Fox"}, "age": 25}]>Sorted by name.last: <#list members?sort_by(['name', 'last']) as m>- ${m.name.last}, ${m.name.first}: ${m.age} years old</#list> chunk:将一个序列分解成几个序列。<#assign seq = ['a', 'b', 'c', 'd', 'e', 'f', 'g', 'h', 'i', 'j']><#list seq?chunk(4) as row>  <#list row as cell>${cell} </#list></#list><#list seq?chunk(4, '-') as row>  <#list row as cell>${cell} </#list></#list>chunk经常用于分栏或者表格输出的格式。五:hash内置方法:keys:values:六:很少使用或者专家级的内置方法:byte,double,float,int,long,short。evalhas_content:变量存在,不是指null也不是空串,一般情况下可以使用expr!?size > 0 or expr!?length > 0 代替expr?has_content。interpret将一个字符串解析为ftl模版,产生一个TemplateTransformModel对象。<#assign x=["a", "b", "c"]><#assign templateSource = "<#list x as y>${y}</#list>"><#assign inlineTemplate = templateSource?interpret><@inlineTemplate>def/@inlineTemplateis_...检查变量类型:

Built-in

Returns true if the value is a ...

is_string

string

is_number[iocblog.net 来源]

number

is_boolean

boolean

is_date

date (all types: date-only, time-only and date-time)

is_method

method

is_transform

transform

is_macro

macro

is_hash

hash

is_hash_ex

extended hash (i.e. supports ?keys and ?values)

is_sequence

sequence

is_collection

collection

is_enumerable

sequence or collection

is_indexable

sequence

is_directive

macro or transform

is_node

node

namespace:返回宏变量的命名空间,只能用于宏。new:创建一个TemplateModel实现的变量。<#assign word_wrapp = "com.acmee.freemarker.WordWrapperTransform"?new()>

转载请注明原文地址: https://www.6miu.com/read-5051810.html

最新回复(0)