
[英]Access Model object in a JSP without using the ModelAndView object?
[英]Using th:object without Model
我想用th:object
为数组的每个元素制作表格。但我出错了。 问题是th:object
仅用于保存在模型上的对象。 如何在th:each
上使用th:object
和th:field
或任何其他想法来解决它?
<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>
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>
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.