SpringMVC----@PathVariable 映射 URL 绑定的占位符(4)

1.带占位符的 URL 是 Spring3.0 新增的功能,该功能在 SpringMVC 向 REST 目标挺进发展过程中具有里程碑的意义

2.通过 @PathVariable 可以将 URL 中占位符参数绑定到控制器处理方法的入参中:

     URL 中的 {xxx} 占位符可以通过@PathVariable("xxx") 绑定到操作方法的入参中。

/**
* @PathVariable可以来映射URL中的占位符到目标方法的参数中。
 * @param id
 * @return
 */
@RequestMapping("/testPathVariable/{id}")
public String testPathVariable(@PathVariable("id") Integer id) {
	System.out.println("testPathVariable: "+ id);
	return SUCCESS;
}

3.即可以通过@PathVariable注解获取到请求URL中的参数,占位符,然后在目标方法中使用。

猜你喜欢

转载自blog.csdn.net/lsh15846393847/article/details/89843543
今日推荐