Java 在呈现页面后,如何从th:each获取项的值,以便将其作为请求参数发送(不使用js)?
我有以下代码:Java 在呈现页面后,如何从th:each获取项的值,以便将其作为请求参数发送(不使用js)?,java,html,spring-boot,thymeleaf,Java,Html,Spring Boot,Thymeleaf,我有以下代码: <tr th:block th:each="participant, iterStat : ${participants}"> <td id="idField" class="table-col-id" th:text="${participant.id}">ex</td> <td class="table-player-name" th:text="${participan
<tr th:block th:each="participant, iterStat : ${participants}">
<td id="idField" class="table-col-id" th:text="${participant.id}">ex</td>
<td class="table-player-name" th:text="${participant.name}">example</td>
<td class="table-col-operation">
<form id="newTournamentRemovePlayerForm"
th:action="@{/tournament/removePlayer?id={id}(id=${participant.id})}"
method="post">
<button class="player-remove-button table-action-button generic-button"
form="newTournamentRemovePlayerForm"
type="submit">Remove</button>
</form>
</td>
</tr>
但是,在当前状态下,无论您单击哪个“移除”按钮,它都会发送最低的id(例如,对于示例表,单击任何移除按钮都会发送“/Tornament/removePlayer?id=1”)
我查了一下百里香的文件:
并尝试使用以下方法:
- iterStat.current.id(发送“1”)
- iterStat.index(发送“0”)
- 和iterStat.count(发送“1”)
没有javascript,有什么方法可以做我需要的事情吗?你把
id
属性搞砸了。id
在整个页面上应该是唯一的,但你在迭代时不会更改它。因此每个表单
都被标识为“NewTournamentRemovePlayPerform”
并且每个按钮都被分配给”NewTournamEntremovePlayPerform“
表单。由于有许多表单,它会退回到第一个表单
您可以修复您的ID,或者更简单地删除它们:
前任
例子
去除
上面的内容应该可以正常工作。谢谢,它可以工作!我没有意识到为迭代期间创建的内容分配id属性会产生这样的结果,但是现在想想,这是非常有意义的。我完全删除了id,因为它不需要(我从代码中需要id的其他地方复制粘贴了表单,但忘了在这里删除它)。
||id||name||action||
|1|john|remove|
|2|jane|remove|
|3|jack|remove|