我有一张地图,我想在Thymeleaf的桌子上呈现。每个键都是一个文档标题,每个值都是一个整数,显示关键字在该文档中出现的次数。
HTML:
<table class="table table-striped table-bordered table-hover">
<tr>
<td>Document Title</td>
<td>Keyword Count</td>
</tr>
<tr th:each="m : ${map}">
<td th:text="${m} + '(' + ${map.get(key)} + ') '"></td>
<td th:text="${m} + '(' + ${map.get(value)} + ') '"></td>
</tr>
</table>
地图
Map<String, Integer> map = combineListsIntoOrderedMap(formattedLinks, countList);
private static Map<String, Integer> combineListsIntoOrderedMap(List<String> keys, List<Integer> values) {
if (keys.size() != values.size())
throw new IllegalArgumentException("Cannot combine lists with dissimilar sizes.");
Map<String, Integer> map = new LinkedHashMap<>();
for (int i = 0; i < keys.size(); i++) {
map.put(keys.get(i), values.get(i));
}
return map;
}
我的输出是一个如下所示的表:
Document Title | Keyword Count
http://www.example.com/doc.doc=1(null) | http://www.example.com/doc.doc=1(null)
应该看起来像:
Document Title | Keyword Count
http://www.example.com/doc.doc | 1