@PathVariable用于获取路径参数,@RequestParam用于获取查询参数(范围路径后?后的key,value形式)。
@GetMapping("/klasses/{klassId}/teachers")
publicList<Teacher>getKlassRelatedTeachers(
@PathVariable("klassId") Long klassId,
@RequestParam(value="type", required=false) String type ) {
...
}
@RequestBody
用于读取 Request 请求的 body 部分并且Content-Type 为 application/json 格式的数据,接收到数据之后会自动将数据绑定到 Java 对象上去。系统会使用HttpMessageConverter或者自定义的HttpMessageConverter将请求的 body 中的 json 字符串转换为 java 对象。
一个请求方法只可以有一个@RequestBody,但是可以有多个@RequestParam和@PathVariable