`
wensong
  • 浏览: 125364 次
  • 性别: Icon_minigender_1
  • 来自: 北京
社区版块
存档分类
最新评论

FreeMarker 知识 积累

阅读更多

一.输出 ${book.name}
空值判断:${book.name?if_exists },
${book.name?default(‘xxx’)}//默认值xxx
${ book.name!"xxx"}//默认值xxx

${ book.name?exists}判断book.name是否存在
日期格式:${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>

分享到:
评论

相关推荐

Global site tag (gtag.js) - Google Analytics