我想用 th:object
为数组的每个元素创建表单。但是我出错了。问题是 th:object
仅用于保存在模型上的对象。如何在 th:object
上使用 th:field
和 th:each
或任何其他想法来解决它?
<tr th:each="sect: ${process.sectionData}" th:if="${sect.sectionType==1}">
<form th:action="@{'/process/section/save/' + ${sect.id} }" method="post" th:object="${sect}">
<td>
<button>
save
</button>
</td>
<td>
<input
type="text"
th:field="*{sect.name}"
class="m-inline"
placeholder="Страна проведения"/>
</td>
</form>
</tr>
答案 0 :(得分:0)
th:field
只是设置输入字段的 name
、id
和 value
的快捷方式。您应该能够做到这一点并让它发挥作用:
<tr th:each="sect: ${process.sectionData}" th:if="${sect.sectionType==1}">
<form th:action="@{'/process/section/save/' + ${sect.id}}" method="post">
<td>
<button>save</button>
</td>
<td>
<input
type="text"
name="name"
th:value="${sect.name}"
class="m-inline"
placeholder="Страна проведения" />
</td>
</form>
</tr>