三.常用语法 EG.一个对象BOOK
1.输出 ${book.name}
空值判断:${book.name?if_exists },
${book.name?default(‘xxx’)}//默认值xxx ${ book.name!"xxx"}//默认值xxx
日期格式:${book.date?string('yyyy-MM-dd')}
数字格式:${book?string.number}--20 ${book?string.currency}--<#-- $20.00 --> ${book?string.percent}—<#-- 20% -->
插入布尔值: <#assign foo=ture /> ${foo?string("yes","no")} <#-- yes -->
2.逻辑判断 a: <#if condition>... <#elseif condition2>... <#elseif condition3>...... <#else>... 其中空值判断可以写成<#if book.name?? >
</#if>
b: <#switch value> <#case refValue1> ... <#break> <#case refValue2> ... <#break> ... <#case refValueN> ... <#break> <#default> ... </#switch>
3.循环读取 <#list sequence as item> ... </#list> 空值判断<#if bookList?size = 0></#list>
e.g. <#list employees as e> ${e_index}. ${e.name} </#list> 输出:
- Readonly
- Robbin