@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/admin,可以输出:

路径上的占位符的值=admin

猜你喜欢

转载自blog.csdn.net/he1234555/article/details/115146824
今日推荐