选择结构
if...else...
<#if condition>
...
<#elseif condition2>
...
<#elseif condition3>
...
<#else>
...
</#if>
<#if x = 1>
x is 1
</#if>
<#if x = 1>
x is 1
<#elseif x = 2>
x is 2
<#elseif x = 3>
x is 3
</#if>
<#if x = 1>
x is 1
<#elseif x = 2>
x is 2
<#elseif x = 3>
x is 3
<#elseif x = 4>
x is 4
<#else>
x is not 1 nor 2 nor 3 nor 4
</#if>
switch...case...default...
<#switch value>
<#case refValue1>
...
<#break>
<#case refValue2>
...
<#break>
<#case refValueN>
...
<#break>
<#default>
...
</#switch>
<#switch being.size>
<#case "small">
This will be processed if it is small
<#break>
<#case "medium">
This will be processed if it is medium
<#break>
<#case "large">
This will be processed if it is large
<#break>
<#default>
This will be processed if it is neither
</#switch>
<#switch x>
<#case x = 1>
1
<#case x = 2>
2
<#default>
d
</#switch>
循环迭代结构
<#list sequence as item>
...
</#list>
<#assign seq = ["winter", "spring", "summer", "autumn"]>
<#list seq as x>
${x_index + 1}. ${x}<#if x_has_next>,</#if>
</#list>
本文详细介绍了Freemarker模板引擎中的if...else...控制结构的使用方法,包括简单的if条件判断、带有elseif的复杂条件判断及包含else的用法,并展示了switch...case...default...结构和循环迭代结构的实现方式。
20万+

被折叠的 条评论
为什么被折叠?



