可以使用 if,elseif ,else指令来条件判断是否跳过模板的一部分,这和程序语言中if是相似的.
语法:
<#if condition>... <#elseif condition2>... <#elseif condition3>... <#else>... </#if>
说明:
示例:
1 //java中准备数据模型 2 root.put("random", new Random().nextInt(100)); 3 root.put("user","张三"); 4 ------------------------------------------------ 5 <#--if语句测试:--> 6 ${user}是<#if user=="老高">我们的老师</#if> 7 ------------------------------------------------ 8 <#--if else 语句测试:--> 9 <#if num0 gt 18> <#--不是使用>,大部分时候,freemarker会把>解释成标签结束! --> 10 及格! 11 <#else> 12 不及格! 13 </#if> 14 --------------------------------------------------- 15 <#-- if else if else语句测试:--> 16 <#if random gte 90> 17 优秀! 18 <#elseif random gte 80> 19 良好! 20 <#else> 21 一般! 22 </#if> 23 ----------------------------------------------------
原文:http://www.cnblogs.com/kjitboy/p/5094142.html