gpt4 book ai didi

java - 在 Thymeleaf 中将 map 渲染到表中的 EL 语法是什么?

转载 作者:行者123 更新时间:2023-12-02 13:11:57 24 4
gpt4 key购买 nike

我有一张 map ,想将其渲染到 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 :

   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

最佳答案

您可以像这样使用keyvalue:

<tr th:each="m : ${map}">
<td th:text="${m.key}">key</td>
<td th:text="${m.value}">value</td>
</tr>

关于java - 在 Thymeleaf 中将 map 渲染到表中的 EL 语法是什么?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/43916860/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com