简体   繁体   English

在 Thymeleaf 循环中显示 ArrayList 内容

[英]Display ArrayList content in Thymeleaf loop

i have problem with display my items from database.我在从数据库中显示我的项目时遇到问题。 I assign my item object to ArrayList and want to display it in html file, every time when I try display it, i have Whitelabel Error Page.我将我的项目 object 分配给 ArrayList 并希望在 html 文件中显示它,每次我尝试显示它时,我都有 Whitelabel 错误页面。 When i display this code below its worked but iteration not.当我在其工作但迭代下方显示此代码时。

HTML: HTML:

<span th:text="${item.get(0).getItemName()}"></span>

^ working ^ 工作

<tr th:each="person, state : ${item}" class="row" th:classappend="${state.odd} ? 'odd-row' : 'even-row'">
    <td th:utext="${item.getItemName()}">Full Name</td>
</tr>

^ Not working ^ 不工作

Java: Java:

List<item> item = new ArrayList<>();
itemRepository.findAll().forEach(item::add);

List<item> findList = new ArrayList<item>();

for (int i = 0; i < item.size(); i++) {
    if(item.get(i).getWhoAdd().equals(isExist.getId())){
        findList.add(item.get(i));
    }
}
model.addAttribute("item",findList);
return "item";

In the code sample you have shown as not working, try using the following在您显示为不工作的代码示例中,尝试使用以下

<td th:text="${person.getItemName()}">Full Name</td>

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM