PathVariable class

Binds a path variable from the URI template to a method parameter.

Path variables are placeholders in URL patterns that are extracted from the actual request URI. They are commonly used in RESTful APIs to identify specific resources.

Parameters

  • value: Name of the path variable (defaults to parameter name)
  • required: Whether the path variable is mandatory (default: true)
  • defaultValue: Fallback value (rarely used for path variables)

Example

@RestController()
class UserController {
  @GetMapping('/users/{userId}/orders/{orderId}')
  Order getOrder(
    @PathVariable('userId') String userId,
    @PathVariable() String orderId  // Uses parameter name 'orderId'
  ) {
    // URL: /users/123/orders/456
    // userId = "123", orderId = "456"
    return orderService.findUserOrder(userId, orderId);
  }
}

Framework Integration

Processed by PathVariableResolver which extracts values from URI template variables.

Inheritance
Annotations
  • @Target.new({TargetKind.parameter})
  • @ResolvedBy(PathVariableResolver())

Constructors

PathVariable({String? value, bool required = true, String? defaultValue})
Binds a path variable from the URI template to a method parameter.
const

Properties

annotationType Type
Returns the annotation _type of this annotation.
no setterinherited
defaultValue String?
Default value to use if the request element is not present.
finalinherited
hashCode int
The hash code for this object.
no setterinherited
required bool
Whether the request element is mandatory.
finalinherited
runtimeType Type
A representation of the runtime type of the object.
no setterinherited
value String?
Name of the request element to bind.
finalinherited

Methods

equalizedProperties() List<Object?>
Mixin-style contract for value-based equality, hashCode, and toString.
inherited
equals(Object other) bool
Checks whether the given object is logically equivalent to this annotation.
inherited
noSuchMethod(Invocation invocation) → dynamic
Invoked when a nonexistent method or property is accessed.
inherited
toString() String
Returns a string representation of this annotation.
inherited

Operators

operator ==(Object other) bool
The equality operator.
inherited