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}