クラス 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 テンプレートの表現。このクラスはスレッドセーフで再利用できるように設計されており、任意の数の展開または一致呼び出しを許可します。

: このクラスは、URI テンプレートを拡張するために内部的に UriComponentsBuilder を使用しますが、これはすでに準備されている 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 = Map.of(
           "booking", "42",
           "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