参数注解
- @PathVariable
获取请求信息 推荐使用rest风格
@GetMapping("/car/{id}/owner/{username}")
使用@PathVariable接收
@PathVariable("id") Integer id,
@PathVariable("username") String name,
//也可以直接使用map<String,String>封装传入的参数
@RequestHeader Map<String,String> header,
- @RequestHeader 获取请求头 用法与上面相同
- @RequestParam 获取请求参数类似:
/test?id=1&msg=adc
用法与上面一样 - @RequestBody获取请求体【post才有请求体】常用获取表单提交的信息,例如:
@PostMapping("/save")
public Map postMethod(@RequestBody String content){
Map<String,Object> map = new HashMap<>();
map.put("content",content);
return map;
}
- @RequestAttribute
获取请求域中的值 可以直接单个获取
@PostMapping("/save")
public Map postMethod(@RequestAttribute("msg") String messgae){
}
也可以直接放在request中
用.getAttribute取值