这两个参数都是用来处理request中的参数值的
但是处理的参数形式(url)不同
@RequestParam 处理的是 http://localhost/paper/editpage?paperId=1
@PathVariable 处理的是 http://localhost/paper/editpage/1
(我这里吧端口号设置为80了,所以直接localhost就行了)
前端页面代码
<a class="btn btn-sm btn-primary"
th:href="@{/paper/editpage/} + ${paper.paperId}" target="_blank" rel="external nofollow" >编辑
<!--经过thymeleaf渲染之后: /paper/editpage/1 -->
</a>
<a class="btn btn-sm btn-primary"
th:href="@{/paper/editpage(paperId=${paper.paperId})}" target="_blank" rel="external nofollow" >测试连接
<!--经过thymeleaf渲染之后: /paper/editpage?paperId=1 -->
</a>
|
经过thymeleaf渲染之后
Controoler处理代码
@GetMapping("/editpage/{paperId}")
public ModelAndView editPage(@PathVariable("paperId") Integer paperId) {
System.out.println("PathVariable:" + paperId);
Paper paper = paperService.selectPaper(paperId);
System.out.println(paper);
return new ModelAndView("paper/addPaper", "paper", paper);
}
@GetMapping("/editpage")
public ModelAndView editPagetest(@RequestParam("paperId") Integer paperId) {
System.out.println("RequestParam:" + paperId);
Paper paper = paperService.selectPaper(paperId);
System.out.println(paper);
return new ModelAndView("paper/addPaper", "paper", paper);
}
|
点击 编辑 按钮之后
点击 测试连接 之后