- 区别
注解 | 支持请求体类型 | 支持请求方法类型 | 支持的Content-Type | 请求示例 |
---|---|---|---|---|
@PathVariable | url请求头 | GET\POST | ALL | url/{}/{},可同时注解多个参数接收 |
@RequestParam | url请求头 | GET | ALL | url?x=x&x=x |
@RequestParam | Bady | POST | from-data,x-www.from-urlencoded | |
@RequestBody | Bady | POST | json |
GET请求
- @RequestParam接收基本类型、基本类型包装类,不支持自定义对象
- 接受参数为自定义对象时,不加任何注解,前台发送对象中的对应属性会自动匹配到对象中。使用@RequestParam注解会报错。
- 接收List<基本数据类型 + String> 时,必须使用@RequestParam注解