freemarker官网资料

一.list

1:_index 与 _has_next
<#assign seq = ["winter", "spring", "summer", "autumn"]>
<#list seq as x>
  ${x_index + 1}. ${x}<#if x_has_next>,</#if>
</#list> 

输出:
引用
1. winter, 2. spring, 3. summer, 4. autumn


2:循环变量
<#assign x=3>
<#list 1..x as i>
  ${i}
</#list>

输出:
引用
1 2 3


如果x=-5则输出:
引用
1 0 -1 -2 -3 -4 -5


3:跳出循环
<#assign seq = ["winter", "spring", "summer", "autumn"]>
<#list seq as x>
   ${x}
   <#if x = "spring"><#break></#if>
</#list>  

输出结果:
引用
winter spring


2:noparse
<#noparse>
    <table>
      <#list animals as being>
      <tr>
          <td>${being.name}<td>${being.price} Euros</td>
      </tr>
      </#list>
    </table>
</#noparse>  

输出结果:
引用

<#list animals as being>
${being.name} ${being.price} Euros


3:compress
<#assign x = "    moo  \n\n   ">

<#compress>
  1 2  3   4    5
  ${x}
  test only

  I said, test only

</#compress>

输出结果:
引用

1 2 3 4 5 moo test only I said, test only

你可能感兴趣的:(java,spring,freemarker)