簡體   English   中英

Thymeleaf 迭代列表

[英]Thymeleaf iterating over a list

我想使用 thymeleaf 迭代一個列表。 我的代碼如下所示:

<ol th:each="test: ${tests}">
    <li th:text="${test.toString()}"></li>
</ol>

此時,tests Set包含2個元素,有一個toString()表示,分別是test1和test2

我在 html 中的輸出如下所示:

1.test1
1.test2

我想知道為什么他們都有數字 1,而不是 1 和 2?

您正在為每個項目而不是 listitem 創建一個有序列表。

這應該有效:

<ol>
    <li th:each="test: ${tests}" th:text="${test.toString()}"></li>
</ol>

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM