@PathVariable使用

Posted zhengjinsheng

tags:

篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了@PathVariable使用相关的知识,希望对你有一定的参考价值。

@PathVariable 映射 URL 绑定的占位符

带占位符的 URL 是 Spring3.0 新增的功能,该功能在SpringMVC 向 REST 目标挺进发展过程中具有里程碑的意义
通过 @PathVariable 可以将 URL 中占位符参数绑定到控制器处理方法的入参中:URL 中的 {xxx} 占位符可以通过@PathVariable(“xxx“) 绑定到操作方法的入参中。
主要是根据请求方法进行类的区别
例子:

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

以上是关于@PathVariable使用的主要内容,如果未能解决你的问题,请参考以下文章

@PathVariable注解使用

为啥使用 PathVariable 而不是 PathParam?

@PathVariable使用

@PathVariable使用

@PathVariable

学习笔记——@PathVariable注解基本使用;@PathVariable注解属性;REST风格CRUD概述;实现PUT&DELETE提交方法步骤;SpringMVC处理请求数据请求头处理