Annotation 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
-
可选元素概要
可选元素
-
元素详细资料
-
value
Alias forname().- 默认值:
- ""
-
name
The name of the path variable to bind to.- 从以下版本开始:
- 4.0
- 默认值:
- ""
-
required
boolean requiredWhether 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 tofalseif you prefer anullor Java 8java.util.Optionalin this case. e.g. on aModelAttributemethod which serves for different requests.- 从以下版本开始:
- 4.0
- 默认值:
- true
-