gpt4 book ai didi

loops - 带有 thymeleaf 的嵌套(双)循环

转载 作者:行者123 更新时间:2023-12-04 23:22:39 26 4
gpt4 key购买 nike

我已经尝试搜索现有的答案,但我找不到它们。

我想从 ArrayList 中的对象访问 ArrayList,所以:

基本上有两个类:词汇表和单词。
Glossary 包含一个包含 Word 对象的列表,Word 类包含一个包含更多 Word 对象(相关单词)的列表

<table>
<span th:each="word : ${glossary.words}">
<td>
<tr th:each="relatedWord: ${word.relatedWords}">
<p th:text="${relatedWord.getName()}"></p>
</tr>
<td>
</span>
</table>

不幸的是,这对我不起作用..

最佳答案

我不确定,但我认为你不能像你一样访问公共(public)的非静态 setter/getter (假设 getName() 被标记为公共(public))。

你应该试试:

<table>
<span th:each="word : ${glossary.words}">
<td>
<tr th:each="relatedWord: ${word.relatedWords}">
<p th:text="${relatedWord.name}"></p>
</tr>
<td>
</span>
</table>

注意:上面的代码绝对不是有效的 XHTML( span 直接在 table 内, tr 直接在 td 内)。

关于loops - 带有 thymeleaf 的嵌套(双)循环,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/19956493/

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