Annotation Interface PathVariable


@Target(PARAMETER) @Retention(RUNTIME) @Documented public @interface PathVariable
Annotation that binds a method variable to a path parameter.

Example

 
  @Controller("/api")
  public class MyController {

      // Incoming request looks like "/api/user/123"
      @GetMapping("/user/{userId}")
      public UserData getUserData(@PathVariable("userId") String theUserId) {
          return UserDao.getUserData(theUserId);
      }
  }
 
 
As you can see, the @PathVariable's parameter name does not need to match the actual method parameter's name.
Since:
1.0
Version:
2022-08-30
  • Optional Element Summary

    Optional Elements
    Modifier and Type
    Optional Element
    Description
    The name of the path variable to map to.
  • Element Details

    • value

      String value
      The name of the path variable to map to.
      Default:
      ""