Freemarker指令

if指令

<#if user=="老李">
这是我们老师老李
<#elseif user=="老王">
这是我们老师老王
<#else>
这是我们老师老高
</#if>

list指令
Java部分代码

//创建数据模型
    Map root = new HashMap();
    root.put("user", "老高");

    List list=new ArrayList();
    list.add(new Address("山西","长治"));
    list.add(new Address("陕西","渭南"));

    root.put("list", list);

a.ftl模板文件代码:

<#list list as sheng>
  <b>${sheng.sheng}</b></br>
</#list>

include指令
创建include.txt文件
a.ftl模板文件代码:

<#include "include.txt"/>

nested指令

<#macro border>
  <table border=4 cellspacing=0 cellpadding=4>
     <tr>
        <td>
          <#nested>

        </td>
     </tr>
  </table>   
</#macro>
<@border>表格中的内容</@border>

定义带参的宏指令

<#macro m1 a b c>
  ${a}--${b}--${c}
</#macro>
<@m1 a="老高" b="老王" c="老李"/>

命名空间
b.ftl模板文件代码

<#macro copyright date>
 <p>copyright(C) ${date}  新的开始</p>
</#macro>
<#assign mail="abc@123.com">

a.ftl模板文件代码

<#import "b.ftl" as b/>
<@b.copyright date="2015-10" />
${b.mail}
<#assign mail="my@123.com" />
${mail}
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值