假设有对象book

一.输出 ${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 –>

二.逻辑判断
1:
<#if condition>
….
<#elseif condition2>
….
<#elseif condition3>
……
<#else>

</#if>
其中空值判断可以写成<#if book.name?? >

2:
<#switch value>
<#case refValue1>
    …
    <#break>
<#case refValue2>
    …
    <#break>

<#case refValueN>
    …
    <#break>
<#default>
    …
</#switch>

三.循环读取
<#list sequence as item>
<#if item_index == 10>
   ${item.id}
   <#break />
</#if>

</#list>
实例:
<#if (post.attachments?size > 0)>
<table width="100%" height="20px" cellpadding="0" cellspacing="0" class="post_bodyTable">
<tbody>
<tr>
<td class="post_body_text" valign="bottom">
相关附件:
<#list post.attachments as attach>
   链接:<a href="${attach.physicalFilename}">${attach.realFilename}</a>&nbsp;
   大小:${attach.filesize}&nbsp;描述:${attach.description}&nbsp;上传日期:${attach.uploadDate}
   <br />
</#list>
</td>
</tr>
</tbody>
</table>
</#if>

Leave a Reply

Your email address will not be published. Required fields are marked *

*

You may use these HTML tags and attributes: <a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code> <del datetime=""> <em> <i> <q cite=""> <strike> <strong>