转自Eve慕
Springboot中使用thymeleaf,在用户列表中希望点击删除按钮就删除当前用户,需要传递当前用户的id。
<table class="table table-bordered table-hover">
<thead>
<tr>
<th>id</th>
<th>用户名</th>
<th>密码</th>
<th>电话</th>
<th>邮箱</th>
<th>操作</th>
</tr>
</thead>
<tbody >
<tr th:each="user : ${userlist}">
<td th:text="${user.userID}"></td>
<td th:text="${user.username}"></td>
<td th:text="${user.password}"></td>
<td th:text="${user.phone}"></td>
<td th:text="${user.email}"></td>
<td><button type="button" class="btn btn-info btn-sm" data-toggle="modal" data-target="#updateModal" th:onclick="'javascript: updateUser('+${user.userID}+')' ">编辑</button>
<!--th:onclick后即为传递参数,在js中就可以接收-->
<button type="button" class="btn btn-danger btn-sm" th:onclick="'javascript:deleteUser('+${user.userID}+')' ">删除</button>
</td>
</tr>
</tbody>
</table>