freemarker常用语法收集

阿超 发表于 2009-08-29 23:23 | 来源: | 阅读 857 次

假设有对象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>

喜欢Java豆技术站点的文章,那就通过 RSS Feed 功能订阅阅读吧!

我要评论

*

* 绝不会泄露



返回首页 | 关于我们 | 联系我们 | 广告合作 | 网站地图 | 友情链接 | 版权声明 | 模板设计