spring - 如何将一个字段的值分配给 Thymeleaf 中其他对象的另一个字段?
问题描述
我想在单击Delete
按钮后删除对象(表中的一行)(每行都有删除按钮。
如何th:object="${userToDelete}"
在表中分配适当的行:逻辑此操作UserToDelete.id = user.id
?
<form th:action="@{/admin/showUsers}" th:object="${userToDelete}" method="post">
<table class="table table-striped">
<thead class="thead-dark">
<tr>
<th>Id</th>
<th>Name</th>
<th>Email</th>
<th></th>
</tr>
</thead>
</tbody>
<tr th:each="user : ${users}">
<td style="color: #000000" th:text="${user.id}">id</td>
<td style="color: #000000" th:text="${user.name}">Name</td>
<td style="color: #000000" th:text="${user.email}">Email</td>
<td>
<div class="form-group">
<input type="submit" value="Delete"
class="btn btn-lg btn-outline-primary btn-block">
</div>
</td>
</tr>
</tbody>
</table>
</form>
解决方案
td
为每个添加tr
:
<td>
<a th:href="${'/admin/delete/' + user.id}">delete</a>
</td>
然后添加GET
端点进行删除 -/admin/delete/{id}
推荐阅读
- json - jq非规范化嵌套字段
- flutter - 在 Flutter 中通用将颜色设置为 App 中的 Text Widget,而无需每次都提及 Widget 内部的主题
- python - 如何点击img元素?
- reactjs - react : 将悬停应用于父 div 内的所有元素
- macos - 忽略 ensurepip 失败:pip 需要 SSL/TLS - Python 3.4.X with pyenv on OS X
- vue.js - 如何在设备为计算机时将 vuetify 抽屉菜单设置为永久,而在设备为移动设备时设置为非永久
- php - 想要从 CSV 文件中获取在 php 的其他列中具有相同值的 ID
- matlab - 在 MATLAB 中验证大数定律
- c++ - 为什么在 pop_back() 操作之后它仍然打印完整的向量?
- python - 仅当数据框中的缺失值介于两个相同值之间时才填充缺失值