该注解主要用于获取路径参数,像url/{id}/{name}
这种形式的参数都可以,get获取post请求均可
@PostMapping("/pathVariable/{id}/{name}")
@ResponseBody
public Map<String, String> pathVariable(
@PathVariable(name = "id") String userId,
@PathVariable(name = "name") String userName) {
Map<String, String> map = new HashMap<>();
map.put("id", userId);
map.put("name", userName);
return map;
}
{
"name": "5566",
"id": "2233"
}