Warning: file_get_contents(/data/phpspider/zhask/data//catemap/3/html/69.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Java 在Thymeleaf循环中显示ArrayList内容_Java_Html_Spring_Model View Controller_Thymeleaf - Fatal编程技术网

Java 在Thymeleaf循环中显示ArrayList内容

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'">

我无法显示数据库中的项目。我将我的项目对象分配给ArrayList,并希望在html文件中显示它,每次尝试显示它时,都会出现白标签错误页面。 当我将此代码显示在其已工作但未迭代的下面时

HTML:


^工作

<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>