1 @RequestBody
使用@RequestBody
方式获取参数,必须使用post
提交方式。如下代码:
@PostMapping("/url")
public String methodA(@RequestBody TeacherQuery teacherQuery) {
}
2 @PathVariable
使用@PathVariable
方式获取参数,使用get
post
delete
等提交方式都可以。但是在url中必须使用占位符,如@RequestMapping("/url/{id}")
。代码如下:
@DeleteMapping("/url/{id}")
public String methodB(@PathVariable String id) {
}
3@RequestParam
使用@RequestParam
方式获取参数,是将请求参数绑定到你控制器的方法参数上(是springmvc中接收普通参数的注解)。代码如下:
@RequestMapping("/url")
public String methodB(@RequestParam(value="name",required=true,defaultValue="hello")String name){
}