文章目录
@RequestAttribute(获取请求域属性)
@PathVariable(获取url中的变量)
@RequestHeader(获取请求头)
可以使用Map获取请求头中的所有键值对
@RequestHeader("User-Agent")
@RequestHeader Map<String,String> headers
@RequestParam(获取请求变量)
可以使用MultiValueMap获取所有请求变量
@RequestParam("age") Integer age,
@RequestParam("inters") List<String> inters,
@RequestParam MultiValueMap<String, String> params
@CookieValue(获取cookie)
@CookieValue("Idea-e4660b8a") String cookie
@RequestBody(获取请求体)
比如form表单中提交的键值对,只有post方式可以携带请求体
@PostMapping(value = "/save")
public Map<String, Object> save(@RequestBody String content){
HashMap<String, Object> map = new HashMap<>();
map.put("content",content);
return map;
}
@MatrixVariable
//1、语法: 请求路径:/cars/sell;low=34;brand=byd,audi,yd
//2、SpringBoot默认是禁用了矩阵变量的功能
// 手动开启:原理。对于路径的处理。UrlPathHelper进行解析。
// removeSemicolonContent(移除分号内容)支持矩阵变量的
//3、矩阵变量必须有url路径变量才能被解析
@GetMapping("/cars/{path}")
public Map carsSell(@MatrixVariable("low") Integer low,
@MatrixVariable("brand") List<String> brand,
@PathVariable("path") String path){
Map<String,Object> map = new HashMap<>();
map.put("low",low);
map.put("brand",brand);
map.put("path",path);
return map;
}