类 RouterFunctions
java.lang.Object
cn.taketoday.web.handler.function.RouterFunctions
Central entry point to Infra functional web framework.
Exposes routing functionality, such as to create a
RouterFunction using a discoverable builder-style API, to
create a RouterFunction
given a RequestPredicate and HandlerFunction, and to do further
subrouting on an existing routing
function.- 从以下版本开始:
- 4.0
- 作者:
- Harry Yang, Arjen Poutsma
-
嵌套类概要
嵌套类修饰符和类型类说明(专用程序包) static class(专用程序包) static final classstatic interfaceRepresents a discoverable builder for router functions.private static final classprivate static final class(专用程序包) static final classA composed routing function that first invokes one function, and then invokes another function (of a different response type) if this route had no result.(专用程序包) static final classRouterFunctions.FilteredRouterFunction<T extends ServerResponse,S extends ServerResponse> Filter the specified handler functions with the given filter function.private static class(专用程序包) static final classA composed routing function that first invokes one function, and then invokes the another function (of the same response typeT) if this route had no result.static interfaceReceives notifications from the logical structure of router functions. -
字段概要
字段修饰符和类型字段说明private static final cn.taketoday.logging.Loggerstatic final StringName of the request attribute that contains the matching pattern, as aPathPattern.static final StringName of the request attribute that contains theServerRequest.static final StringName of the request attribute that contains the URI templates map, mapping variable names to values. -
构造器概要
构造器 -
方法概要
修饰符和类型方法说明static <T extends ServerResponse>
RouterFunction<T>changeParser(RouterFunction<T> routerFunction, PathPatternParser parser) Changes thePathPatternParseron the given router function.static <T extends ServerResponse>
RouterFunction<T>nest(RequestPredicate predicate, RouterFunction<T> routerFunction) Route to the given router function if the given request predicate applies.static Function<ServerRequest,Optional<cn.taketoday.core.io.Resource>> resourceLookupFunction(String pattern, cn.taketoday.core.io.Resource location) Returns the resource lookup function used byresources(String, Resource).static RouterFunction<ServerResponse>Route requests that match the given pattern to resources relative to the given root location.static RouterFunction<ServerResponse>resources(Function<ServerRequest, Optional<cn.taketoday.core.io.Resource>> lookupFunction) Route to resources using the provided lookup function.static RouterFunctions.Builderroute()Offers a discoverable way to create router functions through a builder-style interface.static <T extends ServerResponse>
RouterFunction<T>route(RequestPredicate predicate, HandlerFunction<T> handlerFunction) Route to the given handler function if the given request predicate applies.
-
字段详细资料
-
log
private static final cn.taketoday.logging.Logger log -
REQUEST_ATTRIBUTE
Name of the request attribute that contains theServerRequest. -
URI_TEMPLATE_VARIABLES_ATTRIBUTE
Name of the request attribute that contains the URI templates map, mapping variable names to values. -
MATCHING_PATTERN_ATTRIBUTE
Name of the request attribute that contains the matching pattern, as aPathPattern.
-
-
构造器详细资料
-
RouterFunctions
public RouterFunctions()
-
-
方法详细资料
-
route
Offers a discoverable way to create router functions through a builder-style interface.- 返回:
- a router function builder
-
route
public static <T extends ServerResponse> RouterFunction<T> route(RequestPredicate predicate, HandlerFunction<T> handlerFunction) Route to the given handler function if the given request predicate applies.For instance, the following example routes GET requests for "/user" to the
listUsersmethod inuserController:RouterFunction<ServerResponse> route = RouterFunctions.route(RequestPredicates.GET("/user"), userController::listUsers);- 类型参数:
T- the type of response returned by the handler function- 参数:
predicate- the predicate to testhandlerFunction- the handler function to route to if the predicate applies- 返回:
- a router function that routes to
handlerFunctionifpredicateevaluates totrue - 另请参阅:
-
nest
public static <T extends ServerResponse> RouterFunction<T> nest(RequestPredicate predicate, RouterFunction<T> routerFunction) Route to the given router function if the given request predicate applies. This method can be used to create nested routes, where a group of routes share a common path (prefix), header, or other request predicate.For instance, the following example first creates a composed route that resolves to
listUsersfor a GET, andcreateUserfor a POST. This composed route then gets nested with a "/user" path predicate, so that GET requests for "/user" will list users, and POST request for "/user" will create a new user.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- the type of response returned by the handler function- 参数:
predicate- the predicate to testrouterFunction- the nested router function to delegate to if the predicate applies- 返回:
- a router function that routes to
routerFunctionifpredicateevaluates totrue - 另请参阅:
-
resources
public static RouterFunction<ServerResponse> resources(String pattern, cn.taketoday.core.io.Resource location) Route requests that match the given pattern to resources relative to the given root location. For instanceResource location = new FileSystemResource("public-resources/"); RouterFunction<ServerResponse> resources = RouterFunctions.resources("/resources/**", location);- 参数:
pattern- the pattern to matchlocation- the location directory relative to which resources should be resolved- 返回:
- a router function that routes to resources
- 另请参阅:
-
resourceLookupFunction
public static Function<ServerRequest,Optional<cn.taketoday.core.io.Resource>> resourceLookupFunction(String pattern, cn.taketoday.core.io.Resource location) Returns the resource lookup function used byresources(String, Resource). The returned function can be composed 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 FileSystemResource("public-resources/")) .andThen(resource -> resource.or(() -> defaultResource)); RouterFunction<ServerResponse> resources = RouterFunctions.resources(lookupFunction);- 参数:
pattern- the pattern to matchlocation- the location directory relative to which resources should be resolved- 返回:
- the default resource lookup function for the given parameters.
-
resources
public static RouterFunction<ServerResponse> resources(Function<ServerRequest, Optional<cn.taketoday.core.io.Resource>> lookupFunction) Route to resources using the provided lookup function. If the lookup function provides aResourcefor the given request, it will be it will be exposed using aHandlerFunctionthat handles GET, HEAD, and OPTIONS requests.- 参数:
lookupFunction- the function to provide aResourcegiven theServerRequest- 返回:
- a router function that routes to resources
-
changeParser
public static <T extends ServerResponse> RouterFunction<T> changeParser(RouterFunction<T> routerFunction, PathPatternParser parser) Changes thePathPatternParseron the given router function. This method can be used to change thePathPatternParserproperties from the defaults, for instance to change case sensitivity.- 类型参数:
T- the type of response returned by the handler function- 参数:
routerFunction- the router function to change the parser inparser- the parser to change to.- 返回:
- the change router function
-