thtmeleaf传参
方法一
th:href="@{/editEmp?id=}+${emp.getId()}"
链接形式 http://localhost:8081/editEmp?id=0
接收方法
@GetMapping("/editEmp")
public String editEm(@RequestParam("id")Integer id, Model model){
方法二
th:href="@{/editEmp(id=${t.id})}"
//多个参数
th:href=@{/editEmp(id=${id},name=${name})}
链接形式 http://localhost:8081/editEmp/0
或 http://localhost:8081/editEmp/0/gugugu
接收方法
@GetMapping("/editEmp/{id}")
public String editEm(@PathVariable("id")Integer id, Model model){
//多个参数
@GetMapping("/editEmp/{id}/{name}")
public String editEm(@PathVariable("id")Integer id, @PathVariable("name")String name, Model model){
本文介绍使用Thymeleaf进行页面跳转时的两种传参方式:一种是通过URL拼接参数,另一种是利用路径变量传递参数。具体包括如何在Thymeleaf模板中构造链接地址以及后端控制器如何接收这些参数。

3234

被折叠的 条评论
为什么被折叠?



