@PathVariable

@PathVariable主要作用:映射URL绑定的占位符
带占位符的URL是 Spring3.0 新增的功能,URL中的 {xxx} 占位符可以通过 @PathVariable("xxx") 绑定到操作方法的入参中

例如:

@RequestMapping("/user/{id}")
public String testPathVariable(@PathVariable("id") String id){
    System.out.println("路径上的占位符的值="+id);
    return "success";
}

假如你的请求为localhost:8080/user/shortLink,可以输出:

路径上的占位符的值=shortLink

posted @ 2022-03-04 09:44  想机器猫的大雄  阅读(63)  评论(0)    收藏  举报