0
有三类如何访问与thymeleaf arraylist每个arraylist?
public Class Port{
private String portname;
// with getters and setters
}
public Class Application{
private String appName;
private List<Port> ports= new ArrayList<Port>();
// with getters and setters
}
public Class Service{
private String serviceName;
private List<Application> apps= new ArrayList<Application>();
// with getters and setters
}
下面摘录的是Thymeleaf HTML代码可通过字段进行迭代的一部分。
<form action="#" th:action="@{/processWrapper}" th:object="${service}" method="post">
<table>
<div th:each="app, stat : *{apps}">
<tr>
<td><input type="text" th:field="*{apps[__${stat.index}__].appName}" th:name="|apps[${stat.index}]|" /></td>
<div th:each="port, stat1 : *{app.ports}">
<td><input type="text" th:field="*{app.ports[__${stat1.index}__].portname}" th:name="|app.ports[${stat1.index}]|" /></td>
</div>
</div></table></form>
为什么不工作我得到的错误信息:
属性或字段“口”不能在类型“服务”的对象发现也许不公开?
“服务”有一个名为'ports'的属性吗?其次,你通常使用“公共”和“类”小写。 – bphilipnyc
服务没有端口。服务只有应用程序的Arraylist,其中inturn有端口的数组列表。 代码有正确的大小写。我也更新了上述内容 – user757021