该注解主要用于获取路径参数,像url/{id}/{name}这种形式的参数都可以,get获取post请求均可

    1. @PostMapping("/pathVariable/{id}/{name}")
    2. @ResponseBody
    3. public Map<String, String> pathVariable(
    4. @PathVariable(name = "id") String userId,
    5. @PathVariable(name = "name") String userName) {
    6. Map<String, String> map = new HashMap<>();
    7. map.put("id", userId);
    8. map.put("name", userName);
    9. return map;
    10. }
    1. {
    2. "name": "5566",
    3. "id": "2233"
    4. }