gpt4 book ai didi

java - Spring 和 thymeleaf : Sending an object to a controller from a th:each table

转载 作者:行者123 更新时间:2023-11-29 05:04:23 25 4
gpt4 key购买 nike

我正在使用 thymeleafth:each 属性制作一个经验数据表,我的目标是在每一行中都有一个提交按钮,当点击时,将向我的 Controller 发送一个体验对象,该对象与我在其中单击提交按钮的行相对应。

我不知道出了什么问题,似乎无法在网上找到任何可以帮助解决这个问题的东西。

这是我的网页代码部分:

<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>

这将对用户隐藏您的对象数据,但当他们点击提交时,它将根据需要发送对象数据(而不是像您当前那样发送空表单)。

关于java - Spring 和 thymeleaf : Sending an object to a controller from a th:each table,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/30926136/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com