简体   繁体   English

地图速度表 <String, List<String> &gt;

[英]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.

相关问题 Mybatis如何将另一个表中的列映射到字符串列表? - Mybatis How to map a column from another table to a String list? 从列表中获取值<Map<String, String> &gt; - Get values from List<Map<String, String>> 从列表中获取 json <Map<String,string> &gt; - Get json from List<Map<String,string>> 仅显示列表中的地图键 <Map<String, List<String> &gt;&gt; - Display only map key from List<Map<String, List<String>>> 如何从字符串和列表的映射动态生成表 <String> 使用JSP和Servlet? - How to generate table dynamically from the Map of String and List<String> using JSP and Servlet? 无法从地图投射 <String,Object> 到地图 <String,List<Map<String,String> &gt;&gt; - Cannot cast from Map<String,Object> to Map<String,List<Map<String,String>>> 将HashMap从Map <String,Boolean>反转为Map <Boolean,List <String >> - Reversing a HashMap from Map<String, Boolean> to Map<Boolean, List<String>> 创建一个新地图 <String, List<String> &gt;具有其他地图中的选择性元素 <String, List<String> &gt; - Create a new Map <String, List<String>> with selective elements from another Map <String, List<String>> jpa-创建地图 <String, List<String> &gt;一张桌子的领域 - jpa - create Map<String, List<String>> field with one table 列表/映射中的列表和字符串 - List and String in list/map
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM