freemarker遍历集合

2023-02-21 08:45:15 浏览数 (2)

官方文档:https://freemarker.apache.org/docs/dgui_quickstart_template.html

语法如下:<#list sequence as loopVariable>repeatThis</#list>

例如模板如下:

代码语言:javascript复制
<p>We have these animals:
<table border=1>
  <#list animals as animal>
    <tr><td>${animal.name}<td>${animal.price} Euros
  </#list>
</table>

就会生成

代码语言:javascript复制
<p>We have these animals:
<table border=1>
    <tr><td>mouse<td>50 Euros
    <tr><td>elephant<td>5000 Euros
    <tr><td>python<td>4999 Euros
</table>

这里animal等于是数组里每一项

0 人点赞