java显示Thymeleaf循环中的ArrayList内容
我无法显示数据库中的项目。我将我的item对象分配给ArrayList,并希望在html文件中显示它,每次尝试显示它时,都会出现白标签错误页面。 当我把这段代码显示在其已工作但没有迭代的下面时
HTML:
<span th:text="${item.get(0).getItemName()}"></span>
^工作
<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>
^不工作
爪哇:
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";
# 1 楼答案
在显示为不工作的代码示例中,尝试使用以下命令