FreeMaker commonly used tags

Disclaimer: This article is a blogger original article, follow the CC 4.0 BY-SA copyright agreement, reproduced, please attach the original source link and this statement.
This link: https://blog.csdn.net/xxyybs/article/details/59484267

1, List traversal

**<#-- freemaker注释,此场景为后台传入前台代码List<Object>对象集合。 -->**
<#if (examples.result??)&&(examples.result?size>0)>
    <#list examples.result as object>
        <tr>
            <td>${object.index}</td><#-- 普通从对象取值 -->
            <td>${object.name!''}</td><#-- 取值做非空校验 -->
            <td>${object.date?string('yyyy-MM-dd')!'--'}</td><#-- 时间类型格式化显示 -->
            <td>${typeMap["${object.type!''}"]!'--'}</td<#-- map集合回显:typeMap在后台是Map集合形式传入,根据对象相应的类型当做key值进行不同的内容回显 -->
            <td>${object.interest?string(',##0.00')!'--'}</td><#-- 数字类型显示,取值小数点后两位 -->
        </tr>
    </#list>
<#else>
        <tr>
            <td colspan="10">没有数据!</td>
        </tr>
</#if>

2.Map traversal

**<#-- typeMap<String,String> 从后台填充数据,前台遍历Map集合形成select下拉框,或是显示Map中多条内容 -->**
<#if (typeMap??)&&(typeMap?size>0)>
    <select name="name" id="name">
         <option value="" selected="selected">全部</option>
         <#list typeMap?keys as key>
               <option value="${key}">${typeMap[key]}</option>
         </#list>
    </select>
</#if>
<#-- typeMap集合,根据对象object.type 当做key,获取typeMap value值 -->
<td>${typeMap["${object.type!''}"]!'--'}</td>

3. Common Tags

<#-- freemaker 常用标签 -->
<#if object.time??>${object.time?string('yyyy-MM-dd HH:mm:ss')}<#else>--</#if><#-- 时间类型格式显示 -->
<#if object.data??>
      <#if object.data == 1>
            在线支付
      <#elseif object.data == 2>
            余额还款
      <#else>--
      </#if>
<#else>
     其他
</#if><#-- 根据状态显示不同内容 -->

Attached: freemaker manual link: http://pan.baidu.com/s/1eSIauUu Password: adys

Guess you like

Origin blog.csdn.net/xxyybs/article/details/59484267