我正在使用以下方法制作经验数据表th:each属性与百里香叶我的目标是在每一行都有一个提交按钮,单击该按钮时,会将一个体验对象发送到我的控制器,该对象与我单击提交按钮的行相对应。
我不知道出了什么问题,并且似乎无法在网上找到任何可以帮助解决此问题的内容。
这是我的网页代码部分:
<div th:unless="${#lists.isEmpty(borrower.experiences)}">
<h2>List of Experiences</h2>
<!-- <form ACTION="#" th:action="@{/initiate-edit}" th:object="${experience}"
method="POST">-->
<table id="your-table-id">
<thead>
<tr>
<td>Edit Buttons</td>
<th>Date Planted</th>
<th>Rating</th>
<th>Category</th>
<th>Dept</th>
<th>Resolution</th>
<th>Source</th>
<th>Last Update Date</th>
<th>Last Update Name</th>
<th>Comment</th>
</tr>
</thead>
<tbody>
<tr th:each="experience : ${borrower.experiences}">
<td>
<form ACTION="#" th:action="@{/initiate-edit}"
th:object="${experience}" method="POST">
<!--<a th:href="@{/initiate-edit/}">CLICK</a>-->
<button type="submit">Submit</button>
</form>
</td>
<td th:text="${experience.experienceDate}">13/01/2014</td>
<td th:text="${experience.rating}">4</td>
<td th:text="${experience.categoryShortDesc}">Account and Billing</td>
<td th:text="${experience.deptDesc}">Account and Billing</td>
<td th:text="${experience.resolutionShortTx}">Account and Billing</td>
<td th:text="${experience.source}">Account and Billing</td>
<td th:text="${experience.lastUpdateDate}">Account and Billing</td>
<td th:text="${experience.lastUpdatedName}">Account and Billing</td>
<td th:text="${experience.commentsShort}">Account and Billing</td>
</tr>
</tbody>
</table>
</div>
这是我将其发送到的方法:
@RequestMapping(value = "/initiate-edit", method = RequestMethod.POST)
public String initiateEdit(@AuthenticationPrincipal final User user,
@ModelAttribute("SpringWeb")CustomerExperience editableExperience, final Model model) {
LOG.info("THIS IS A TEST!!!" + editableExperience.getSsn());
model.addAttribute("editableExperience", editableExperience);
return EDIT_PAGE;
}
您需要在发送输入时填写表单:
<form ACTION="#" th:action="@{/initiate-edit}" th:object="${experience}" method="POST">
<input type="hidden" th:field="*{experienceDate}"/>
<input type="hidden" th:field="*{rating}"/>
<!-- ADD ALL THE OTHER FIELDS THAT ARE PART OF THE OBJECT -->
<button type="submit">Submit</button>
</form>
这将对用户隐藏您的对象数据,但当他们单击提交时,它将根据需要发送对象数据(而不是像您当前那样发送空表单)。
本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系:hwhale#tublm.com(使用前将#替换为@)