在springboot的controller中常用的参数注解有:@PathVariable、@RequestHeader、@ModelAttribute、@RequestParam、@MatrixVariable、@CookieValue、@RequestBody
其中每一个注解的作用可参考下面的例子
@GetMapping("/car/{id}/owner/{owner}")publicMap<String,Object>getCar(@PathVariable("id")Integer id,//路径变量//路径变量@PathVariable("owner")String name,//批量获取路径变量@PathVariableMap<String,String> pv,//获取单个请求头@RequestHeader("User-Agent")String userAgent,//批量获取请求头@RequestHeaderMap<String,String> header,//获取单个请求参数@RequestParam("age")Integer age,//获取单个数组请求参数@RequestParam("inters")List<String> inters,//获取所有请求参数@RequestParam("inters")Map<String,String>params,//获取cookies的值@CookieValue("_ga")String _ga){Map<String,Object>map=newHashMap<>();
map.put("id",id);
map.put("name",name);
map.put("pv",pv);
map.put("userAgent",userAgent);
map.put("header",header);return map;}