クラス RouterFunctions

java.lang.ObjectSE
org.springframework.web.servlet.function.RouterFunctions

public abstract class RouterFunctions extends ObjectSE
Spring の関数 WebMvc フレームワークへのメインエントリポイント。発見可能なビルダースタイルの API を使用して RouterFunction を作成したり、RequestPredicate および HandlerFunction を指定して RouterFunction を作成したり、既存のルーティング関数でさらにサブルーチン化したりするなど、ルーティング機能を公開します。
導入:
5.2
作成者:
Arjen Poutsma, Sebastien Deleuze, Rossen Stoyanchev
  • フィールドの詳細

    • REQUEST_ATTRIBUTE

      public static final StringSE REQUEST_ATTRIBUTE
      ServerRequest を含むリクエスト属性の名前。
    • URI_TEMPLATE_VARIABLES_ATTRIBUTE

      public static final StringSE URI_TEMPLATE_VARIABLES_ATTRIBUTE
      変数名を値にマッピングする、URI テンプレートマップを含むリクエスト属性の名前。
    • MATCHING_PATTERN_ATTRIBUTE

      public static final StringSE MATCHING_PATTERN_ATTRIBUTE
      PathPattern として、一致するパターンを含むリクエスト属性の名前。
  • コンストラクターの詳細

    • RouterFunctions

      public RouterFunctions()
  • メソッドの詳細

    • route

      public static RouterFunctions.Builder route()
      ビルダースタイルのインターフェースを介してルーター関数を作成する発見可能な方法を提供します。
      戻り値:
      ルーター関数ビルダー
    • route

      public static <T extends ServerResponse> RouterFunction<T> route(RequestPredicate predicate, HandlerFunction<T> handlerFunction)
      指定されたリクエスト述語が適用される場合、指定されたハンドラー関数にルーティングします。

      たとえば、次の例では、"/user" の GET リクエストを userController の listUsers メソッドにルーティングします。

      RouterFunction<ServerResponse> route =
          RouterFunctions.route(RequestPredicates.GET("/user"), userController::listUsers);
      
      型パラメーター:
      T - ハンドラー関数によって返されるレスポンスの型
      パラメーター:
      predicate - テストする述語
      handlerFunction - 述語が適用される場合にルーティングするハンドラー関数
      戻り値:
      predicate が true と評価された場合に handlerFunction にルーティングするルーター関数
      関連事項:
    • nest

      public static <T extends ServerResponse> RouterFunction<T> nest(RequestPredicate predicate, RouterFunction<T> routerFunction)
      指定されたリクエスト述語が適用される場合、指定されたルーター関数にルーティングします。これは、ルートのグループが共通のパス(プレフィックス)、ヘッダー、その他のリクエスト述語を共有するネストされたルートを作成するために使用できます。

      たとえば、次の例では、最初に、GET の場合は listUsers に、POST の場合は createUser に解決される合成ルートを作成します。次に、この構成されたルートは "/user" パス述語でネストされるため、"/user" の GET リクエストはユーザーをリストし、"/user" の POST リクエストは新しいユーザーを作成します。

      RouterFunction<ServerResponse> userRoutes =
          RouterFunctions.route(RequestPredicates.method(HttpMethod.GET), this::listUsers)
              .andRoute(RequestPredicates.method(HttpMethod.POST), this::createUser);
      
      RouterFunction<ServerResponse> nestedRoute =
          RouterFunctions.nest(RequestPredicates.path("/user"), userRoutes);
      
      型パラメーター:
      T - ハンドラー関数によって返されるレスポンスの型
      パラメーター:
      predicate - テストする述語
      routerFunction - 述語が適用される場合に委譲するネストされたルーター関数
      戻り値:
      predicate が true と評価された場合に routerFunction にルーティングするルーター関数
      関連事項:
    • resource

      public static RouterFunction<ServerResponse> resource(RequestPredicate predicate, Resource resource)
      指定された述語に一致するリクエストを指定されたリソースにルーティングします。例:
      Resource resource = new ClassPathResource("static/index.html");
      RouterFunction<ServerResponse> resources = RouterFunctions.resource(path("/api/**").negate(), resource);
      
      パラメーター:
      predicate - 一致する述語
      resource - 提供するリソース
      戻り値:
      リソースにルーティングするルーター関数
      導入:
      6.1.4
    • resource

      public static RouterFunction<ServerResponse> resource(RequestPredicate predicate, Resource resource, BiConsumerSE<Resource, HttpHeaders> headersConsumer)
      指定された述語に一致するリクエストを指定されたリソースにルーティングします。例:
      Resource resource = new ClassPathResource("static/index.html")
      RouterFunction<ServerResponse> resources = RouterFunctions.resource(path("/api/**").negate(), resource);
      
      パラメーター:
      predicate - 一致する述語
      resource - 提供するリソース
      headersConsumer - 提供されるリソースの HTTP ヘッダーへのアクセスを提供します
      戻り値:
      リソースにルーティングするルーター関数
      導入:
      6.1.4
    • resources

      public static RouterFunction<ServerResponse> resources(StringSE pattern, Resource location)
      指定されたパターンに一致するリクエストを、指定されたルートロケーションを基準としたリソースにルーティングします。例:
      Resource location = new FileUrlResource("public-resources/");
      RouterFunction<ServerResponse> resources = RouterFunctions.resources("/resources/**", location);
      
      パラメーター:
      pattern - マッチングするパターン
      location - リソースを解決する必要のある場所のディレクトリ
      戻り値:
      リソースにルーティングするルーター関数
      関連事項:
    • resources

      public static RouterFunction<ServerResponse> resources(StringSE pattern, Resource location, BiConsumerSE<Resource, HttpHeaders> headersConsumer)
      指定されたパターンに一致するリクエストを、指定されたルートロケーションを基準としたリソースにルーティングします。例:
      Resource location = new FileUrlResource("public-resources/");
      RouterFunction<ServerResponse> resources = RouterFunctions.resources("/resources/**", location);
      
      パラメーター:
      pattern - マッチングするパターン
      location - リソースを解決する必要のある場所のディレクトリ
      headersConsumer - 提供されるリソースの HTTP ヘッダーへのアクセスを提供します
      戻り値:
      リソースにルーティングするルーター関数
      導入:
      6.1
      関連事項:
    • resourceLookupFunction

      public static FunctionSE<ServerRequest, OptionalSE<Resource>> resourceLookupFunction(StringSE pattern, Resource location)
      Returns the resource lookup function used by resources(String, Resource) . The returned function can be composedSE on. For instance to return a default resource when the lookup function does not match:
      Optional<Resource> defaultResource = Optional.of(new ClassPathResource("index.html"));
      
      Function<ServerRequest, Optional<Resource>> lookupFunction =
          RouterFunctions.resourceLookupFunction("/resources/**", new FileUrlResource("public-resources/"))
              .andThen(resource -> resource.or(() -> defaultResource));
      
      RouterFunction<ServerResponse> resources = RouterFunctions.resources(lookupFunction);
      
      パラメーター:
      pattern - マッチングするパターン
      location - リソースを解決する必要のある場所のディレクトリ
      戻り値:
      指定されたパラメーターのデフォルトのリソース検索関数。
      関連事項:
    • resources

      public static RouterFunction<ServerResponse> resources(FunctionSE<ServerRequest, OptionalSE<Resource>> lookupFunction)
      提供された検索機能を使用してリソースにルーティングします。ルックアップ関数が指定されたリクエストに Resource を提供する場合、GET、HEAD、OPTIONS リクエストを処理する HandlerFunction を使用して公開されます。
      パラメーター:
      lookupFunction - Resource を提供する機能
      戻り値:
      リソースにルーティングするルーター関数
    • resources

      public static RouterFunction<ServerResponse> resources(FunctionSE<ServerRequest, OptionalSE<Resource>> lookupFunction, BiConsumerSE<Resource, HttpHeaders> headersConsumer)
      提供された検索機能を使用してリソースにルーティングします。ルックアップ関数が指定されたリクエストに Resource を提供する場合、GET、HEAD、OPTIONS リクエストを処理する HandlerFunction を使用して公開されます。
      パラメーター:
      lookupFunction - Resource を提供する機能
      headersConsumer - 提供されるリソースの HTTP ヘッダーへのアクセスを提供します
      戻り値:
      リソースにルーティングするルーター関数
      導入:
      6.1
    • changeParser

      public static <T extends ServerResponse> RouterFunction<T> changeParser(RouterFunction<T> routerFunction, PathPatternParser parser)
      Changes the PathPatternParser on the given router function. This method can be used to change the PathPatternParser properties from the defaults. For instance to change case sensitivity.
      型パラメーター:
      T - ハンドラー関数によって返されるレスポンスの型
      パラメーター:
      routerFunction - パーサーを変更するルーター関数
      parser - 変更するパーサー
      戻り値:
      ルーター変更機能