【发布时间】:2015-09-04 17:28:21
【问题描述】:
我正在使用带有 Thymeleaf 的 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;
}
【问题讨论】:
-
你应该描述你的问题是什么。据我所知,您提交了一个不发送数据的表单。首先,您要提交的数据应在您的表单中。
-
很抱歉,这是我在 Stack Overflow 上的第一篇文章,所以我仍在试图弄清楚它是如何工作的,哈哈。但我的问题是我试图将“体验”对象(位于我的 th:object 标签内)发送到我的控制器方法。我想访问整个对象本身,而不仅仅是在表中创建的数据行。这更有意义吗?
-
是的,我明白了,看看 Aeseir 的回答,这就是我所说的。虽然我必须说我会使用 javascript
标签: java html spring spring-mvc thymeleaf