@RequestParam,@PathParam,@PathVariable等注解区别
来源:互联网 发布:大数据框架hadoop 编辑:程序博客网 时间:2024/06/14 11:39
@RequestParam
和 @PathVariable
注解是用于从request中接收请求的,两个都可以接收参数,关键点不同的是@RequestParam
是从request里面拿取值,而@PathVariable
是从一个URI模板里面来填充
@RequestParam
看下面一段代码:
http://localhost:8080/springmvc/hello/101?param1=10¶m2=20
根据上面的这个URL,你可以用这样的方式来进行获取
public String getDetails( @RequestParam(value="param1", required=true) String param1, @RequestParam(value="param2", required=false) String param2){...}
- 1
- 2
- 3
- 4
- 5
@RequestParam
支持下面四种参数
- defaultValue 如果本次请求没有携带这个参数,或者参数为空,那么就会启用默认值
- name 绑定本次参数的名称,要跟URL上面的一样
- required 这个参数是不是必须的
- value 跟name一样的作用,是name属性的一个别名
@PathVariable
这个注解能够识别URL里面的一个模板,我们看下面的一个URL
http://localhost:8080/springmvc/hello/101?param1=10¶m2=20
- 1
上面的一个url你可以这样写:
@RequestMapping("/hello/{id}") public String getDetails(@PathVariable(value="id") String id, @RequestParam(value="param1", required=true) String param1, @RequestParam(value="param2", required=false) String param2){.......}
- 1
- 2
- 3
- 4
- 5
- 6
区别很明显了
@PathParam
这个注解是和spring的pathVariable
是一样的,也是基于模板的,但是这个是jboss包下面的一个实现,上面的是spring的一个实现,都要导包
@QueryParam
@QueryParam
是 JAX-RS 本来就提供的,和Spring的RequestParam作用一致
@ResponseBody
responseBody表示服务器返回的时候以一种什么样的方式进行返回, 将内容或对象作为 HTTP 响应正文返回,值有很多,一般设定为json
@RequestBody
一般是post请求的时候才会使用这个请求,把参数丢在requestbody里面
转载自:http://blog.csdn.net/u011410529/article/details/66974974
阅读全文
0 0
- @RequestParam,@PathParam,@PathVariable等注解区别
- @RequestParam,@PathParam,@PathVariable等注解区别
- @RequestParam、@RequestBody、@PathVariable 等注解详解
- spring 注解@PathVariable和@RequestParam的区别
- springMVC的@RequestParam注解和@PathVariable注解的区别
- springMVC的@RequestParam注解和@PathVariable注解的区别
- springMVC的@RequestParam注解和@PathVariable注解的区别
- @RequestParam @RequestBody @PathVariable 等参数绑定注解详解
- Spring MVC之注解Annonatoin之@RequestParam @RequestBody @PathVariable 等
- @RequestParam @RequestBody @PathVariable 等参数绑定注解详解
- @RequestParam @RequestBody @PathVariable 等参数绑定注解详解
- @RequestParam @RequestBody @PathVariable 等参数绑定注解详解
- @RequestParam @RequestBody @PathVariable 等参数绑定注解详解(转载)
- @RequestParam @RequestBody @PathVariable 等参数绑定注解详解
- @RequestParam @RequestBody @PathVariable 等参数绑定注解详解
- @RequestParam @RequestBody @PathVariable 等参数绑定注解详解
- @RequestParam @RequestBody @PathVariable 等参数绑定注解详解
- @RequestParam @RequestBody @PathVariable 等参数绑定注解详解
- Mysql数据库导入导出
- Vim编辑nginx配置文件时高亮显示
- 安卓WebView问题总汇(持续更新)
- PHP实现选择排序算法
- ebpf 实例
- @RequestParam,@PathParam,@PathVariable等注解区别
- POJ1446 Girls and Boys
- 欢迎使用CSDN-markdown编辑器
- 坑爹的logstash条件判断
- 中小企业迎品牌建设最佳契机 中企动力赋能数字化智能经营
- 正则表达式手机号(大陆,香港)
- Java 内部类知识点
- 什么是热修复技术
- 导弹拦截系统(附详细讲解,误喷)