public class PathPattern extends Object implements Comparable<PathPattern>
PathPattern matches URL paths using the following rules:
? matches one character* matches zero or more characters within a path segment** matches zero or more path segments until the end of the path{spring} matches a path segment and captures it as a variable named "spring"{spring:[a-z]+} matches the regexp [a-z]+ as a path variable named "spring"{*spring} matches zero or more path segments until the end of the path
and captures it as a variable named "spring"Note: In contrast to
AntPathMatcher, ** is supported only
at the end of a pattern. For example /pages/{**} is valid but
/pages/{**}/details is not. The same applies also to the capturing
variant {*spring}. The aim is to eliminate ambiguity when
comparing patterns for specificity.
/pages/t?st.html — matches /pages/test.html as well as
/pages/tXst.html but not /pages/toast.html/resources/*.png — matches all .png files in the
resources directory/resources/** — matches all files
underneath the /resources/ path, including /resources/image.png
and /resources/css/spring.css/resources/{*path} — matches all files
underneath the /resources/, as well as /resources, and captures
their relative path in a variable named "path"; /resources/image.png
will match with "path" → "/image.png", and /resources/css/spring.css
will match with "path" → "/css/spring.css"/resources/{filename:\\w+}.dat will match /resources/spring.dat
and assign the value "spring" to the filename variablePathContainer| Modifier and Type | Class and Description |
|---|---|
static class |
PathPattern.PathMatchInfo
Holder for URI variables and path parameters (matrix variables) extracted
based on the pattern for a given matched path.
|
static class |
PathPattern.PathRemainingMatchInfo
Holder for the result of a match on the start of a pattern.
|
| Modifier and Type | Field and Description |
|---|---|
static Comparator<PathPattern> |
SPECIFICITY_COMPARATOR
Comparator that sorts patterns by specificity as follows:
Null instances are last.
|
| Modifier and Type | Method and Description |
|---|---|
PathPattern |
combine(PathPattern pattern2string)
Combine this pattern with another.
|
int |
compareTo(PathPattern otherPattern)
Compare this pattern with a supplied pattern: return -1,0,+1 if this pattern
is more specific, the same or less specific than the supplied pattern.
|
boolean |
equals(Object other) |
PathContainer |
extractPathWithinPattern(PathContainer path)
Determine the pattern-mapped part for the given path.
|
String |
getPatternString()
Return the original String that was parsed to create this PathPattern.
|
int |
hashCode() |
boolean |
hasPatternSyntax()
Whether the pattern string contains pattern syntax that would require
use of
matches(PathContainer), or if it is a regular String that
could be compared directly to others. |
PathPattern.PathMatchInfo |
matchAndExtract(PathContainer pathContainer)
Match this pattern to the given URI path and return extracted URI template
variables as well as path parameters (matrix variables).
|
boolean |
matches(PathContainer pathContainer)
Whether this pattern matches the given path.
|
PathPattern.PathRemainingMatchInfo |
matchStartOfPath(PathContainer pathContainer)
Match the beginning of the given path and return the remaining portion
not covered by this pattern.
|
String |
toString() |
public static final Comparator<PathPattern> SPECIFICITY_COMPARATOR
public String getPatternString()
public boolean hasPatternSyntax()
matches(PathContainer), or if it is a regular String that
could be compared directly to others.public boolean matches(PathContainer pathContainer)
pathContainer - the candidate path to attempt to match againsttrue if the path matches this pattern@Nullable public PathPattern.PathMatchInfo matchAndExtract(PathContainer pathContainer)
pathContainer - the candidate path to attempt to match againstnull for no match@Nullable public PathPattern.PathRemainingMatchInfo matchStartOfPath(PathContainer pathContainer)
pathContainer - the candidate path to attempt to match againstnull for no matchpublic PathContainer extractPathWithinPattern(PathContainer path)
For example:
/docs/cvs/commit.html' and '/docs/cvs/commit.html → ''/docs/*' and '/docs/cvs/commit' → 'cvs/commit'/docs/cvs/*.html' and '/docs/cvs/commit.html → 'commit.html'/docs/**' and '/docs/cvs/commit → 'cvs/commit'Notes:
matches(org.springframework.http.server.PathContainer) returns true for
the same path but does not enforce this.
path - a path that matches this patternpublic int compareTo(@Nullable PathPattern otherPattern)
compareTo in interface Comparable<PathPattern>public PathPattern combine(PathPattern pattern2string)