Java 在Thymeleaf循环中显示ArrayList内容
我无法显示数据库中的项目。我将我的项目对象分配给ArrayList,并希望在html文件中显示它,每次尝试显示它时,都会出现白标签错误页面。 当我将此代码显示在其已工作但未迭代的下面时 HTML:Java 在Thymeleaf循环中显示ArrayList内容,java,html,spring,model-view-controller,thymeleaf,Java,Html,Spring,Model View Controller,Thymeleaf,我无法显示数据库中的项目。我将我的项目对象分配给ArrayList,并希望在html文件中显示它,每次尝试显示它时,都会出现白标签错误页面。 当我将此代码显示在其已工作但未迭代的下面时 HTML: ^工作 <tr th:each="person, state : ${item}" class="row" th:classappend="${state.odd} ? 'odd-row' : 'even-row'">
^工作
<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=new ArrayList();
itemRepository.findAll().forEach(item::add);
List findList=new ArrayList();
对于(int i=0;i
在您显示为不工作的代码示例中,尝试使用以下内容
<td th:text="${person.getItemName()}">Full Name</td>
全名
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";
<td th:text="${person.getItemName()}">Full Name</td>