下面用代码来演示@PathVariable传参方式

@RequestMapping("/user/{id}")
public String test(@PathVariable("id") Integer id){
     System.out.println(id);
     return "hello";
 }

  在@RequestMapping中请求路径,将需要传递的参数用{}括起来。通过@PathVariable("参数名称")来获取url中的参数值。要求@PathVariable中参数名称必须和url中参数名称一致

 

  例如:访问  /user/1          ------------  对应id=1

        /user/2           ------------  对应id=2

 

本文转自:http://www.cnblogs.com/caoyc/p/5635300.html

相关文章:

  • 2021-10-20
  • 2021-07-13
  • 2022-02-01
  • 2021-06-28
  • 2021-07-21
  • 2022-12-23
猜你喜欢
  • 2022-12-23
  • 2021-12-05
  • 2021-05-13
  • 2022-01-01
  • 2021-05-31
  • 2022-12-23
  • 2021-10-19
相关资源
相似解决方案