Annotation Interface PathVariable


@Documented @RequestParam @Target(PARAMETER) @Retention(RUNTIME) public @interface PathVariable
This annotation may be used to annotate method parameters on request mappings where a URI-template has been used in the path-mapping of the RequestMapping annotation. The method parameter may be of type String, any Java primitive type or any boxed version thereof.

For example:-


 @RequestMapping("/bookings/{guest-id}")
 public class BookingController {

     @RequestMapping
     public void processBookingRequest(@PathVariable("guest-id") String guestID) {
         // process booking from the given guest here
     }
 }
 

For example:-


 @RequestMapping("/rewards/{vip-level}")
 public class RewardController {

     @RequestMapping
     public void processReward(@PathVariable("vip-level") Integer vipLevel) {
         // process reward here
     }
 }
 
作者:
TODAY 2018-06-29 16:27:12
  • 可选元素概要

    可选元素
    修饰符和类型
    可选元素
    说明
    The name of the path variable to bind to.
    boolean
    Whether the path variable is required.
    Alias for name().
  • 元素详细资料

    • value

      @AliasFor("name") String value
      Alias for name().
      默认值:
      ""
    • name

      @AliasFor("value") String name
      The name of the path variable to bind to.
      从以下版本开始:
      4.0
      默认值:
      ""
    • required

      boolean required
      Whether the path variable is required.

      Defaults to true, leading to an exception being thrown if the path variable is missing in the incoming request. Switch this to false if you prefer a null or Java 8 java.util.Optional in this case. e.g. on a ModelAttribute method which serves for different requests.

      从以下版本开始:
      4.0
      默认值:
      true