文章目录
- 前言
- 一、前端表格同一行传参
- 1.table
- 2.超链接的注解URL后加传递的参数
- 3.按钮的点击事件后加传递的参数
前言
本篇主要介绍在 thymleaf 里获取表格某一行的值,如 id。
一、前端表格同一行传参
1.table
table 里 thymleaf each 遍历展示数据用法。
<table class="table table-bordered table-hover"><tbody class="text-center"><tr><th>学生ID</th><th>学生姓名</th><th>请假天数</th><th>请假理由</th><th>是否同意</th></tr><tr th:each="sf:${stu_fudaoyuan}"><td th:text="${sf.leaveid}">1</td><td th:text="${sf.leavename}">张三</td><td th:text="${sf.leaveday}">1</td><td th:text="${sf.leavereason}">回家</td>
<!-- <td th:text="${od.agree}"></td>--><td th:text="'是'"></td></tr></tbody></table>
2.超链接的注解URL后加传递的参数
超链接可以用注解URL后面加传递的参数,但是在 里点击按钮无效。
这里跳转到 controller 层的 /delTest 注解。
<td><a th:href="@{/delTest(id=${sf.leaveid})}">delTest</a></td>
@GetMapping("/delTest")public String delete(Long id) {System.out.println("id:" + id);return null;}
3.按钮的点击事件后加传递的参数
button 使用点击事件后面加传递的参数。
js 语句里点击事件直接传参。
<td><button th:onclick="'javascript:deleteUser('+${sf.leaveid}+')' ">delTest</button></td>
<script>function deleteUser(id){alert(id);}
</script>