クラス UriTemplate

java.lang.ObjectSE
org.springframework.web.util.UriTemplate
実装されたすべてのインターフェース:
SerializableSE

public class UriTemplate extends ObjectSE implements SerializableSE
expand(Map)expand(Object[]) を介して URI 変数で展開できる、match(String) を介して URL に一致させることができる URI テンプレートの表現。このクラスは、スレッドセーフで再利用できるように設計されており、任意の数の展開呼び出しまたは一致呼び出しを許可します。

: このクラスは内部で UriComponentsBuilder を使用して URI テンプレートを展開し、すでに準備されている URI テンプレートへのショートカットにすぎません。URI エンコーディングなど、より動的な準備と追加の柔軟性のために、UriComponentsBuilder にいくつかのエンコーディングモードを追加する UriComponentsBuilder またはより高レベルの DefaultUriBuilderFactory の使用を検討してください。詳細については、リファレンスドキュメントを参照してください。

導入:
3.0
作成者:
Arjen Poutsma, Juergen Hoeller, Rossen Stoyanchev
関連事項:
  • コンストラクターの詳細

    • UriTemplate

      public UriTemplate(StringSE uriTemplate)
      指定された URI 文字列で新しい UriTemplate を構築します。
      パラメーター:
      uriTemplate - URI テンプレート文字列
  • メソッドの詳細

    • getVariableNames

      public ListSE<StringSE> getVariableNames()
      テンプレート内の変数の名前を順番に返します。
      戻り値:
      テンプレート変数名
    • expand

      public URISE expand(MapSE<StringSE,?> uriVariables)
      変数のマップを指定すると、このテンプレートを URI に展開します。マップキーは変数名、マップ値は変数値を表します。変数の順序は重要ではありません。

      例:

       UriTemplate template = new UriTemplate("https://example.com/hotels/{hotel}/bookings/{booking}");
       Map<String, String> uriVariables = new HashMap<String, String>();
       uriVariables.put("booking", "42");
       uriVariables.put("hotel", "Rest & Relax");
       System.out.println(template.expand(uriVariables));
       
      出力されます:
      https://example.com/hotels/Rest%20%26%20Relax/bookings/42
      パラメーター:
      uriVariables - URI 変数のマップ
      戻り値:
      拡張 URI
      例外:
      IllegalArgumentExceptionSE - uriVariables が null の場合。または、すべての変数名の値が含まれていない場合
    • expand

      public URISE expand(ObjectSE... uriVariableValues)
      変数の配列を指定して、このテンプレートを完全な URI に展開します。配列は変数値を表します。変数の順序は重要です。

      例:

       UriTemplate template = new UriTemplate("https://example.com/hotels/{hotel}/bookings/{booking}");
       System.out.println(template.expand("Rest & Relax", 42));
       
      出力されます:
      https://example.com/hotels/Rest%20%26%20Relax/bookings/42
      パラメーター:
      uriVariableValues - URI 変数の配列
      戻り値:
      拡張 URI
      例外:
      IllegalArgumentExceptionSE - uriVariables が null である場合、または十分な変数が含まれていない場合
    • matches

      public boolean matches(@Nullable StringSE uri)
      指定された URI がこのテンプレートと一致するかどうかを示します。
      パラメーター:
      uri - 照合する URI
      戻り値:
      一致する場合は true。それ以外の場合は false 
    • match

      public MapSE<StringSE,StringSE> match(StringSE uri)
      指定された URI を変数値のマップに一致させます。返されたマップのキーは変数名であり、値は指定された URI で発生した変数値です。

      例:

       UriTemplate template = new UriTemplate("https://example.com/hotels/{hotel}/bookings/{booking}");
       System.out.println(template.match("https://example.com/hotels/1/bookings/42"));
       
      出力されます:
      {hotel=1, booking=42}
      パラメーター:
      uri - 照合する URI
      戻り値:
      変数値のマップ
    • toString

      public StringSE toString()
      オーバーライド:
      クラス ObjectSEtoString