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