1、路径参数path
当请求如:http://localhost:8080/test/1
,需要使用@PathVariable接收参数。
@RequestMapping("/test/{id}")
public void test(@PathVariable("id") Long id){
}
2、查询参数query
当请求将参数拼接到url尾部的,如:http://localhost:8080/test?name=1
,需要使用@RequestParam接收参数。参数名要和传递的参数名字一致 如果非要不一致的可以在参数前添加@RequestParam(“xxx”)
@RequestMapping("/test")
public void test(@RequestParam String name) {
}
3、请求体参数body
前端使用post方式,将参数写在body中进行传输,可以按照属性名,使用map或者实体类接收。
@PostMapping("/test")
public void test(@RequestBody Stu stu) {
}