Warning: file_get_contents(/data/phpspider/zhask/data//catemap/5/spring-mvc/2.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

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/5/spring-mvc/2.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:在<;中循环迭代;部门>;标记并创建行。_Java_Spring Mvc_Thymeleaf - Fatal编程技术网

Java Thymeleaf:在<;中循环迭代;部门>;标记并创建行。

Java Thymeleaf:在<;中循环迭代;部门>;标记并创建行。,java,spring-mvc,thymeleaf,Java,Spring Mvc,Thymeleaf,我不熟悉thymeleaf,尝试使用thymeleafth:each属性迭代值,但输出错误。我使用的是而不是table,当thymeleaf呈现页面时,所有对象的值都会覆盖第一行的值,其余的行都是空的。以下是我的代码: 我的Spring MVC控制器代码 ProductCategory category = new ProductCategory(); category.setId(BigInteger.valueOf(558711)); category.setTitle("Category

我不熟悉
thymeleaf
,尝试使用
thymeleaf
th:each
属性迭代值,但输出错误。我使用的是
而不是table,当thymeleaf呈现页面时,所有对象的值都会覆盖第一行的值,其余的行都是空的。以下是我的代码:

我的Spring MVC控制器代码

ProductCategory category = new ProductCategory();
category.setId(BigInteger.valueOf(558711));
category.setTitle("Category 1");
category.setStatus(FinEnum.STATUS.IN_ACTIVE.getStatus());

ProductCategory category2 = new ProductCategory();
category.setId(BigInteger.valueOf(558722));
category.setTitle("Category 2");
category.setStatus(FinEnum.STATUS.ACTIVE.getStatus());

List<ProductCategory> categories = new ArrayList<ProductCategory>();
categories.add(category);
categories.add(category2);

model.addAttribute("categories", categories);
return "admin/product/view-categories";
ProductCategory=newproductcategory();
category.setId(biginger.valueOf(558711));
类别。设定名称(“类别1”);
category.setStatus(FinEnum.STATUS.IN_ACTIVE.getStatus());
ProductCategory category2=新ProductCategory();
category.setId(biginger.valueOf(558722));
类别。设定名称(“类别2”);
category.setStatus(FinEnum.STATUS.ACTIVE.getStatus());
列表类别=新建ArrayList();
类别。添加(类别);
类别。添加(类别2);
model.addAttribute(“类别”,categories);
返回“管理员/产品/视图类别”;
我的手机号码:

<div class="row-area" th:each="category: ${categories}">
                    <div class="column2 tariff-date" style="width: 15%;"><span th:text="${category.id}">Dummy Data</span></div>
                    <div class="column2 tariff-date" style="width: 15%;"><span th:text="${category.title}">Dummy Data</span></div>
                    <div class="column2 tariff-date" style="width: 13%;"><span th:text="${category.status}">Dummy Data</span></div>
                    <div class="column5 icons middle-area" style="margin-left: 7px; width: 40%;">
                        <a href="javascript:void(0)" class="diplay-none"></a>
                        <a class="icon7" href="javascript:void(0)" style="width: 140px;">View Sub Category</a>
                        <a class="icon2" href="javascript:void(0)"><p>Edit</p></a>
                        <div th:switch="${category.status}" style="margin-left: 195px;">
                            <a class="icon8" href="javascript:void(0)" th:case="'Inactive'" style="width: 88px;">Deactivate</a>
                            <a class="icon9" href="javascript:void(0)" th:case="'Active'">Active</a>
                        </div>
                        <a class="icon14" href="javascript:void(0)" style="width: 60px;"><p>Delete</p></a>
                    </div>
                </div>

虚拟数据
虚拟数据
虚拟数据
我的输出是:


问题与Thymeleaf无关,只是一个简单的打字错误。行后:

ProductCategory category2 = new ProductCategory();
您仍在修改(覆盖)
类别
对象,而不是
类别2
。因此,
category2
的属性从未设置。更正代码应为:

category2.setId(BigInteger.valueOf(558722));
category2.setTitle("Category 2");
category2.setStatus(FinEnum.STATUS.ACTIVE.getStatus());

在本地进行了测试,我们在修复后看到了“行”数据。

你能先尝试一下吗?删除hello@erhun我已经尝试过了,但仍然得到了这个输出。是的,@Martin我已经找到了答案。谢谢你的回答。