【发布时间】:2017-09-19 22:51:08
【问题描述】:
一共有三个类
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
}
下面的 sn-p 是 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>
为什么它不起作用?我收到错误消息:
在“服务”类型的对象上找不到属性或字段“端口”可能不是公共的?
【问题讨论】:
-
Service是否有一个名为ports的属性?其次,您通常将public和class设为小写。 -
服务没有端口。服务只有应用程序的 Arraylist,而应用程序又具有端口数组列表。代码有正确的大小写。我也更新了以上内容
标签: html spring-boot thymeleaf