[英]Velocity table from Map<String, List<String>>
I want to create a table within a Velocity template which gets it data from a Map<String, List<String>>
. 我想在Velocity模板中创建一个表,该表从
Map<String, List<String>>
获取数据。 I tried it with nested foreach
loops, but for some reason it didn't work (empty table even if data is present). 我用嵌套的
foreach
循环进行了尝试,但是由于某种原因,它不起作用(即使存在数据也为空表)。
Adding the data to my model 将数据添加到我的模型
model.put("downloaded", holder.getDownloadedFiles());
this adds a map as described above. 这将如上所述添加地图。
my template: 我的模板:
<table >
<tr>
<th style="width:150px">Subsystem</th>
<th style="width:500px">Filename</th>
</tr>
#foreach( $system in $downloaded.keySet)
#foreach($file in ${downloaded.get($system)})
<tr>
#if($foreach.count == 1) ##do only once
<td rowspan=$downloaded.get($system).size()>$system</td>
#end
<td>$file</td>
</tr>
#end
#end
</table>
For now I would be happy, to have a table like this (key should be 1 cell over multiple columns): 现在,我很高兴拥有这样一个表(键应该是多列中的1个单元格):
key value1
value2
value3
value4
key2 value1
value2
value3
value4
Do I access variables right and call methods properly? 我可以正确访问变量并正确调用方法吗?
Instead of 代替
#foreach( $system in $downloaded.keySet)
for the outer loop you should use 对于外循环,您应该使用
#foreach( $system in $downloaded.keySet())
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.