public class PathPattern extends ObjectSE implements ComparableSE<PathPattern>
PathPattern
は、次のルールを使用して URL パスを照合します。
?
は 1 文字に一致する *
は、パスセグメント内の 0 個以上の文字に一致する **
は、パスの終わりまでゼロ個以上のパスセグメントと一致する {spring}
はパスセグメントと一致し、「spring」という名前の変数としてキャプチャーする {spring:[a-z]+}
は、「spring」という名前のパス変数として正規表現 [a-z]+
と一致します。{*spring}
は、パスの終わりまでゼロ個以上のパスセグメントと一致し、「spring」という名前の変数としてキャプチャーする 注意 : AntPathMatcher
とは対照的に、**
はパターンの最後でのみサポートされます。たとえば、/pages/{**}
は有効ですが、/pages/{**}/details
は無効です。同じことがキャプチャーバリアント {*spring}
にも当てはまります。目的は、特異性についてパターンを比較する際のあいまいさを排除することです。
/pages/t?st.html
— /pages/test.html
および /pages/tXst.html
と一致しますが、/pages/toast.html
とは一致しません /resources/*.png
— resources
ディレクトリ内のすべての .png
ファイルに一致する /resources/**
— /resources/image.png
および /resources/css/spring.css
を含む、/resources/
パスにあるすべてのファイルに一致する /resources/{*path}
— /resources/
パスにあるすべてのファイルに一致し、それらの相対パスを「path」という名前の変数にキャプチャーします。/resources/image.png
は「パス」と一致します。→ "/image.png"、および /resources/css/spring.css
は " パス "→"/css/spring.css" と一致します /resources/{filename:\\w+}.dat
は /resources/spring.dat
と一致し、値 "spring"
を filename
変数に割り当てます PathContainer
修飾子と型 | クラスと説明 |
---|---|
static class | PathPattern.PathMatchInfo 指定された一致パスのパターンに基づいて抽出された URI 変数およびパスパラメーター(マトリックス変数)のホルダー。 |
static class | PathPattern.PathRemainingMatchInfo パターンの開始での一致の結果のホルダー。 |
修飾子と型 | フィールドと説明 |
---|---|
static ComparatorSE<PathPattern> | SPECIFICITY_COMPARATOR パターンを次のように特異性でソートするコンパレータ: null インスタンスは最後です。 |
修飾子と型 | メソッドと説明 |
---|---|
PathPattern | combine(PathPattern pattern2string) このパターンを別のパターンと組み合わせます。 |
int | compareTo(PathPattern otherPattern) このパターンを提供されたパターンと比較します。このパターンがより具体的である場合、-1、0、+ 1 を返します。これは、提供されたパターンと同じか、より具体的ではありません。 |
boolean | equals(ObjectSE other) |
PathContainer | extractPathWithinPattern(PathContainer path) 指定されたパスのパターンマッピングされた部分を決定します。 |
StringSE | getPatternString() この PathPattern を作成するために解析された元の文字列を返します。 |
int | hashCode() |
boolean | hasPatternSyntax() パターン文字列に matches(PathContainer) の使用を必要とするパターン構文が含まれているか、他の文字列と直接比較できる通常の文字列であるか。 |
PathPattern.PathMatchInfo | matchAndExtract(PathContainer pathContainer) このパターンを指定された URI パスに一致させ、抽出された URI テンプレート変数とパスパラメーター(マトリックス変数)を返します。 |
boolean | matches(PathContainer pathContainer) このパターンが指定されたパスに一致するかどうか。 |
PathPattern.PathRemainingMatchInfo | matchStartOfPath(PathContainer pathContainer) 指定されたパスの先頭に一致し、このパターンでカバーされていない残りの部分を返します。 |
StringSE | toString() |
cloneSE, finalizeSE, getClassSE, notifySE, notifyAllSE, waitSE, waitSE, waitSE
public static final ComparatorSE<PathPattern> SPECIFICITY_COMPARATOR
public StringSE getPatternString()
public boolean hasPatternSyntax()
matches(PathContainer)
の使用を必要とするパターン構文が含まれているか、他の文字列と直接比較できる通常の文字列であるか。public boolean matches(PathContainer pathContainer)
pathContainer
- 照合を試みる候補パス true
@Nullable public PathPattern.PathMatchInfo matchAndExtract(PathContainer pathContainer)
pathContainer
- 照合を試みる候補パス null
@Nullable public PathPattern.PathRemainingMatchInfo matchStartOfPath(PathContainer pathContainer)
pathContainer
- 照合を試みる候補パス null
public PathContainer extractPathWithinPattern(PathContainer path)
例:
/docs/cvs/commit.html
' および '/docs/cvs/commit.html
→ ''/docs/*
' および '/docs/cvs/commit
'→ 'cvs/commit
'/docs/cvs/*.html
' および '/docs/cvs/commit.html
→ 'commit.html
'/docs/**
' および '/docs/cvs/commit
→ 'cvs/commit
'注:
matches(org.springframework.http.server.PathContainer)
が同じパスに対して true
を返すと仮定しますが、これを強制しません。path
- このパターンに一致するパス public int compareTo(@Nullable PathPattern otherPattern)
ComparableSE<PathPattern>
の compareToSE
public PathPattern combine(PathPattern pattern2string)
public int hashCode()
ObjectSE
の hashCodeSE
public StringSE toString()
ObjectSE
の toStringSE