类 RouterFunctionBuilder
- 所有已实现的接口:
RouterFunctions.Builder
RouterFunctions.Builder.- 从以下版本开始:
- 4.0
- 作者:
- Arjen Poutsma, Harry Yang
-
嵌套类概要
嵌套类修饰符和类型类说明private static classRouter function returned bybuild()that simply iterates over the registered routes. -
字段概要
字段修饰符和类型字段说明private final ArrayList<HandlerFilterFunction<ServerResponse,ServerResponse>> private final ArrayList<HandlerFilterFunction<ServerResponse,ServerResponse>> private final ArrayList<RouterFunction<ServerResponse>> -
构造器概要
构造器 -
方法概要
修饰符和类型方法说明private RouterFunctions.Builderadd(RequestPredicate predicate, HandlerFunction<ServerResponse> handlerFunction) add(RouterFunction<ServerResponse> routerFunction) Adds the given route to this builder.after(BiFunction<ServerRequest, ServerResponse, ServerResponse> responseProcessor) Filter the response object for all routes created by this builder with the given response processing function.before(Function<ServerRequest, ServerRequest> requestProcessor) Filter the request object for all routes created by this builder with the given request processing function.build()Builds theRouterFunction.DELETE(HandlerFunction<ServerResponse> handlerFunction) Adds a route to the given handler function that handles HTTPDELETErequests.DELETE(RequestPredicate predicate, HandlerFunction<ServerResponse> handlerFunction) Adds a route to the given handler function that handles all HTTPDELETErequests that match the given predicate.DELETE(String pattern, HandlerFunction<ServerResponse> handlerFunction) Adds a route to the given handler function that handles all HTTPDELETErequests that match the given pattern.DELETE(String pattern, RequestPredicate predicate, HandlerFunction<ServerResponse> handlerFunction) Adds a route to the given handler function that handles all HTTPDELETErequests that match the given pattern and predicate.filter(HandlerFilterFunction<ServerResponse, ServerResponse> filterFunction) Filters all routes created by this builder with the given filter function.GET(HandlerFunction<ServerResponse> handlerFunction) Adds a route to the given handler function that handles HTTPGETrequests.GET(RequestPredicate predicate, HandlerFunction<ServerResponse> handlerFunction) Adds a route to the given handler function that handles all HTTPGETrequests that match the given predicate.GET(String pattern, HandlerFunction<ServerResponse> handlerFunction) Adds a route to the given handler function that handles all HTTPGETrequests that match the given pattern.GET(String pattern, RequestPredicate predicate, HandlerFunction<ServerResponse> handlerFunction) Adds a route to the given handler function that handles all HTTPGETrequests that match the given pattern and predicate.HEAD(HandlerFunction<ServerResponse> handlerFunction) Adds a route to the given handler function that handles HTTPHEADrequests.HEAD(RequestPredicate predicate, HandlerFunction<ServerResponse> handlerFunction) Adds a route to the given handler function that handles all HTTPHEADrequests that match the given predicate.HEAD(String pattern, HandlerFunction<ServerResponse> handlerFunction) Adds a route to the given handler function that handles all HTTPHEADrequests that match the given pattern.HEAD(String pattern, RequestPredicate predicate, HandlerFunction<ServerResponse> handlerFunction) Adds a route to the given handler function that handles all HTTPHEADrequests that match the given pattern and predicate.nest(RequestPredicate predicate, Consumer<RouterFunctions.Builder> builderConsumer) Route to a built router function if the given request predicate applies.nest(RequestPredicate predicate, Supplier<RouterFunction<ServerResponse>> routerFunctionSupplier) Route to the supplied router function if the given request predicate applies.onError(Class<? extends Throwable> exceptionType, BiFunction<Throwable, ServerRequest, ServerResponse> responseProvider) Filters all exceptions of the given type by applying the given response provider function.onError(Predicate<Throwable> predicate, BiFunction<Throwable, ServerRequest, ServerResponse> responseProvider) Filters all exceptions that match the predicate by applying the given response provider function.OPTIONS(HandlerFunction<ServerResponse> handlerFunction) Adds a route to the given handler function that handles HTTPOPTIONSrequests.OPTIONS(RequestPredicate predicate, HandlerFunction<ServerResponse> handlerFunction) Adds a route to the given handler function that handles all HTTPOPTIONSrequests that match the given predicate.OPTIONS(String pattern, HandlerFunction<ServerResponse> handlerFunction) Adds a route to the given handler function that handles all HTTPOPTIONSrequests that match the given pattern.OPTIONS(String pattern, RequestPredicate predicate, HandlerFunction<ServerResponse> handlerFunction) Adds a route to the given handler function that handles all HTTPOPTIONSrequests that match the given pattern and predicate.PATCH(HandlerFunction<ServerResponse> handlerFunction) Adds a route to the given handler function that handles HTTPPATCHrequests.PATCH(RequestPredicate predicate, HandlerFunction<ServerResponse> handlerFunction) Adds a route to the given handler function that handles all HTTPPATCHrequests that match the given predicate.PATCH(String pattern, HandlerFunction<ServerResponse> handlerFunction) Adds a route to the given handler function that handles all HTTPPATCHrequests that match the given pattern.PATCH(String pattern, RequestPredicate predicate, HandlerFunction<ServerResponse> handlerFunction) Adds a route to the given handler function that handles all HTTPPATCHrequests that match the given pattern and predicate.path(String pattern, Consumer<RouterFunctions.Builder> builderConsumer) Route to a built router function if the given path prefix pattern applies.path(String pattern, Supplier<RouterFunction<ServerResponse>> routerFunctionSupplier) Route to the supplied router function if the given path prefix pattern applies.POST(HandlerFunction<ServerResponse> handlerFunction) Adds a route to the given handler function that handles HTTPPOSTrequests.POST(RequestPredicate predicate, HandlerFunction<ServerResponse> handlerFunction) Adds a route to the given handler function that handles all HTTPPOSTrequests that match the given predicate.POST(String pattern, HandlerFunction<ServerResponse> handlerFunction) Adds a route to the given handler function that handles all HTTPPOSTrequests that match the given pattern.POST(String pattern, RequestPredicate predicate, HandlerFunction<ServerResponse> handlerFunction) Adds a route to the given handler function that handles all HTTPPOSTrequests that match the given pattern and predicate.PUT(HandlerFunction<ServerResponse> handlerFunction) Adds a route to the given handler function that handles HTTPPUTrequests.PUT(RequestPredicate predicate, HandlerFunction<ServerResponse> handlerFunction) Adds a route to the given handler function that handles all HTTPPUTrequests that match the given predicate.PUT(String pattern, HandlerFunction<ServerResponse> handlerFunction) Adds a route to the given handler function that handles all HTTPPUTrequests that match the given pattern.PUT(String pattern, RequestPredicate predicate, HandlerFunction<ServerResponse> handlerFunction) Adds a route to the given handler function that handles all HTTPPUTrequests that match the given pattern and predicate.Route requests that match the given pattern to resources relative to the given root location.resources(Function<ServerRequest, Optional<cn.taketoday.core.io.Resource>> lookupFunction) Route to resources using the provided lookup function.route(RequestPredicate predicate, HandlerFunction<ServerResponse> handlerFunction) Adds a route to the given handler function that handles all requests that match the given predicate.withAttribute(String name, Object value) Add an attribute with the given name and value to the last route built with this builder.withAttributes(Consumer<Map<String, Object>> attributesConsumer) Manipulate the attributes of the last route built with the given consumer.
-
字段详细资料
-
routerFunctions
-
errorHandlers
-
filterFunctions
-
-
构造器详细资料
-
RouterFunctionBuilder
RouterFunctionBuilder()
-
-
方法详细资料
-
add
从接口复制的说明:RouterFunctions.BuilderAdds the given route to this builder. Can be used to merge externally defined router functions into this builder, or can be combined withRouterFunctions.route(RequestPredicate, HandlerFunction)to allow for more flexible predicate matching.For instance, the following example adds the router function returned from
OrderController.routerFunction(). to thechangeUsermethod inuserController:RouterFunction<ServerResponse> route = RouterFunctions.route() .GET("/users", userController::listUsers) .add(orderController.routerFunction()); .build();- 指定者:
add在接口中RouterFunctions.Builder- 参数:
routerFunction- the router function to be added- 返回:
- this builder
- 另请参阅:
-
add
private RouterFunctions.Builder add(RequestPredicate predicate, HandlerFunction<ServerResponse> handlerFunction) -
GET
从接口复制的说明:RouterFunctions.BuilderAdds a route to the given handler function that handles HTTPGETrequests.- 指定者:
GET在接口中RouterFunctions.Builder- 参数:
handlerFunction- the handler function to handle allGETrequests- 返回:
- this builder
-
GET
public RouterFunctions.Builder GET(RequestPredicate predicate, HandlerFunction<ServerResponse> handlerFunction) 从接口复制的说明:RouterFunctions.BuilderAdds a route to the given handler function that handles all HTTPGETrequests that match the given predicate.- 指定者:
GET在接口中RouterFunctions.Builder- 参数:
predicate- predicate to matchhandlerFunction- the handler function to handle allGETrequests that matchpredicate- 返回:
- this builder
- 另请参阅:
-
GET
从接口复制的说明:RouterFunctions.BuilderAdds a route to the given handler function that handles all HTTPGETrequests that match the given pattern.- 指定者:
GET在接口中RouterFunctions.Builder- 参数:
pattern- the pattern to match tohandlerFunction- the handler function to handle allGETrequests that matchpattern- 返回:
- this builder
-
GET
public RouterFunctions.Builder GET(String pattern, RequestPredicate predicate, HandlerFunction<ServerResponse> handlerFunction) 从接口复制的说明:RouterFunctions.BuilderAdds a route to the given handler function that handles all HTTPGETrequests that match the given pattern and predicate.For instance, the following example routes GET requests for "/user" that accept JSON to the
listUsersmethod inuserController:RouterFunction<ServerResponse> route = RouterFunctions.route() .GET("/user", RequestPredicates.accept(MediaType.APPLICATION_JSON), userController::listUsers) .build();- 指定者:
GET在接口中RouterFunctions.Builder- 参数:
pattern- the pattern to match topredicate- additional predicate to matchhandlerFunction- the handler function to handle allGETrequests that matchpatternand the predicate- 返回:
- this builder
- 另请参阅:
-
HEAD
从接口复制的说明:RouterFunctions.BuilderAdds a route to the given handler function that handles HTTPHEADrequests.- 指定者:
HEAD在接口中RouterFunctions.Builder- 参数:
handlerFunction- the handler function to handle allHEADrequests- 返回:
- this builder
-
HEAD
public RouterFunctions.Builder HEAD(RequestPredicate predicate, HandlerFunction<ServerResponse> handlerFunction) 从接口复制的说明:RouterFunctions.BuilderAdds a route to the given handler function that handles all HTTPHEADrequests that match the given predicate.- 指定者:
HEAD在接口中RouterFunctions.Builder- 参数:
predicate- predicate to matchhandlerFunction- the handler function to handle allHEADrequests that matchpredicate- 返回:
- this builder
- 另请参阅:
-
HEAD
public RouterFunctions.Builder HEAD(String pattern, HandlerFunction<ServerResponse> handlerFunction) 从接口复制的说明:RouterFunctions.BuilderAdds a route to the given handler function that handles all HTTPHEADrequests that match the given pattern.- 指定者:
HEAD在接口中RouterFunctions.Builder- 参数:
pattern- the pattern to match tohandlerFunction- the handler function to handle allHEADrequests that matchpattern- 返回:
- this builder
-
HEAD
public RouterFunctions.Builder HEAD(String pattern, RequestPredicate predicate, HandlerFunction<ServerResponse> handlerFunction) 从接口复制的说明:RouterFunctions.BuilderAdds a route to the given handler function that handles all HTTPHEADrequests that match the given pattern and predicate.- 指定者:
HEAD在接口中RouterFunctions.Builder- 参数:
pattern- the pattern to match topredicate- additional predicate to matchhandlerFunction- the handler function to handle allHEADrequests that matchpattern- 返回:
- this builder
-
POST
从接口复制的说明:RouterFunctions.BuilderAdds a route to the given handler function that handles HTTPPOSTrequests.- 指定者:
POST在接口中RouterFunctions.Builder- 参数:
handlerFunction- the handler function to handle allPOSTrequests- 返回:
- this builder
-
POST
public RouterFunctions.Builder POST(RequestPredicate predicate, HandlerFunction<ServerResponse> handlerFunction) 从接口复制的说明:RouterFunctions.BuilderAdds a route to the given handler function that handles all HTTPPOSTrequests that match the given predicate.- 指定者:
POST在接口中RouterFunctions.Builder- 参数:
predicate- predicate to matchhandlerFunction- the handler function to handle allPOSTrequests that matchpredicate- 返回:
- this builder
- 另请参阅:
-
POST
public RouterFunctions.Builder POST(String pattern, HandlerFunction<ServerResponse> handlerFunction) 从接口复制的说明:RouterFunctions.BuilderAdds a route to the given handler function that handles all HTTPPOSTrequests that match the given pattern.- 指定者:
POST在接口中RouterFunctions.Builder- 参数:
pattern- the pattern to match tohandlerFunction- the handler function to handle allPOSTrequests that matchpattern- 返回:
- this builder
-
POST
public RouterFunctions.Builder POST(String pattern, RequestPredicate predicate, HandlerFunction<ServerResponse> handlerFunction) 从接口复制的说明:RouterFunctions.BuilderAdds a route to the given handler function that handles all HTTPPOSTrequests that match the given pattern and predicate.For instance, the following example routes POST requests for "/user" that contain JSON to the
addUsermethod inuserController:RouterFunction<ServerResponse> route = RouterFunctions.route() .POST("/user", RequestPredicates.contentType(MediaType.APPLICATION_JSON), userController::addUser) .build();- 指定者:
POST在接口中RouterFunctions.Builder- 参数:
pattern- the pattern to match topredicate- additional predicate to matchhandlerFunction- the handler function to handle allPOSTrequests that matchpattern- 返回:
- this builder
-
PUT
从接口复制的说明:RouterFunctions.BuilderAdds a route to the given handler function that handles HTTPPUTrequests.- 指定者:
PUT在接口中RouterFunctions.Builder- 参数:
handlerFunction- the handler function to handle allPUTrequests- 返回:
- this builder
-
PUT
public RouterFunctions.Builder PUT(RequestPredicate predicate, HandlerFunction<ServerResponse> handlerFunction) 从接口复制的说明:RouterFunctions.BuilderAdds a route to the given handler function that handles all HTTPPUTrequests that match the given predicate.- 指定者:
PUT在接口中RouterFunctions.Builder- 参数:
predicate- predicate to matchhandlerFunction- the handler function to handle allPUTrequests that matchpredicate- 返回:
- this builder
- 另请参阅:
-
PUT
从接口复制的说明:RouterFunctions.BuilderAdds a route to the given handler function that handles all HTTPPUTrequests that match the given pattern.- 指定者:
PUT在接口中RouterFunctions.Builder- 参数:
pattern- the pattern to match tohandlerFunction- the handler function to handle allPUTrequests that matchpattern- 返回:
- this builder
-
PUT
public RouterFunctions.Builder PUT(String pattern, RequestPredicate predicate, HandlerFunction<ServerResponse> handlerFunction) 从接口复制的说明:RouterFunctions.BuilderAdds a route to the given handler function that handles all HTTPPUTrequests that match the given pattern and predicate.For instance, the following example routes PUT requests for "/user" that contain JSON to the
editUsermethod inuserController:RouterFunction<ServerResponse> route = RouterFunctions.route() .PUT("/user", RequestPredicates.contentType(MediaType.APPLICATION_JSON), userController::editUser) .build();- 指定者:
PUT在接口中RouterFunctions.Builder- 参数:
pattern- the pattern to match topredicate- additional predicate to matchhandlerFunction- the handler function to handle allPUTrequests that matchpattern- 返回:
- this builder
-
PATCH
从接口复制的说明:RouterFunctions.BuilderAdds a route to the given handler function that handles HTTPPATCHrequests.- 指定者:
PATCH在接口中RouterFunctions.Builder- 参数:
handlerFunction- the handler function to handle allPATCHrequests- 返回:
- this builder
-
PATCH
public RouterFunctions.Builder PATCH(RequestPredicate predicate, HandlerFunction<ServerResponse> handlerFunction) 从接口复制的说明:RouterFunctions.BuilderAdds a route to the given handler function that handles all HTTPPATCHrequests that match the given predicate.- 指定者:
PATCH在接口中RouterFunctions.Builder- 参数:
predicate- predicate to matchhandlerFunction- the handler function to handle allPATCHrequests that matchpredicate- 返回:
- this builder
- 另请参阅:
-
PATCH
public RouterFunctions.Builder PATCH(String pattern, HandlerFunction<ServerResponse> handlerFunction) 从接口复制的说明:RouterFunctions.BuilderAdds a route to the given handler function that handles all HTTPPATCHrequests that match the given pattern.- 指定者:
PATCH在接口中RouterFunctions.Builder- 参数:
pattern- the pattern to match tohandlerFunction- the handler function to handle allPATCHrequests that matchpattern- 返回:
- this builder
-
PATCH
public RouterFunctions.Builder PATCH(String pattern, RequestPredicate predicate, HandlerFunction<ServerResponse> handlerFunction) 从接口复制的说明:RouterFunctions.BuilderAdds a route to the given handler function that handles all HTTPPATCHrequests that match the given pattern and predicate.For instance, the following example routes PATCH requests for "/user" that contain JSON to the
editUsermethod inuserController:RouterFunction<ServerResponse> route = RouterFunctions.route() .PATCH("/user", RequestPredicates.contentType(MediaType.APPLICATION_JSON), userController::editUser) .build();- 指定者:
PATCH在接口中RouterFunctions.Builder- 参数:
pattern- the pattern to match topredicate- additional predicate to matchhandlerFunction- the handler function to handle allPATCHrequests that matchpattern- 返回:
- this builder
-
DELETE
从接口复制的说明:RouterFunctions.BuilderAdds a route to the given handler function that handles HTTPDELETErequests.- 指定者:
DELETE在接口中RouterFunctions.Builder- 参数:
handlerFunction- the handler function to handle allDELETErequests- 返回:
- this builder
-
DELETE
public RouterFunctions.Builder DELETE(RequestPredicate predicate, HandlerFunction<ServerResponse> handlerFunction) 从接口复制的说明:RouterFunctions.BuilderAdds a route to the given handler function that handles all HTTPDELETErequests that match the given predicate.- 指定者:
DELETE在接口中RouterFunctions.Builder- 参数:
predicate- predicate to matchhandlerFunction- the handler function to handle allDELETErequests that matchpredicate- 返回:
- this builder
- 另请参阅:
-
DELETE
public RouterFunctions.Builder DELETE(String pattern, HandlerFunction<ServerResponse> handlerFunction) 从接口复制的说明:RouterFunctions.BuilderAdds a route to the given handler function that handles all HTTPDELETErequests that match the given pattern.- 指定者:
DELETE在接口中RouterFunctions.Builder- 参数:
pattern- the pattern to match tohandlerFunction- the handler function to handle allDELETErequests that matchpattern- 返回:
- this builder
-
DELETE
public RouterFunctions.Builder DELETE(String pattern, RequestPredicate predicate, HandlerFunction<ServerResponse> handlerFunction) 从接口复制的说明:RouterFunctions.BuilderAdds a route to the given handler function that handles all HTTPDELETErequests that match the given pattern and predicate.- 指定者:
DELETE在接口中RouterFunctions.Builder- 参数:
pattern- the pattern to match topredicate- additional predicate to matchhandlerFunction- the handler function to handle allDELETErequests that matchpattern- 返回:
- this builder
-
OPTIONS
从接口复制的说明:RouterFunctions.BuilderAdds a route to the given handler function that handles HTTPOPTIONSrequests.- 指定者:
OPTIONS在接口中RouterFunctions.Builder- 参数:
handlerFunction- the handler function to handle allOPTIONSrequests- 返回:
- this builder
-
OPTIONS
public RouterFunctions.Builder OPTIONS(RequestPredicate predicate, HandlerFunction<ServerResponse> handlerFunction) 从接口复制的说明:RouterFunctions.BuilderAdds a route to the given handler function that handles all HTTPOPTIONSrequests that match the given predicate.- 指定者:
OPTIONS在接口中RouterFunctions.Builder- 参数:
predicate- predicate to matchhandlerFunction- the handler function to handle allOPTIONSrequests that matchpredicate- 返回:
- this builder
- 另请参阅:
-
OPTIONS
public RouterFunctions.Builder OPTIONS(String pattern, HandlerFunction<ServerResponse> handlerFunction) 从接口复制的说明:RouterFunctions.BuilderAdds a route to the given handler function that handles all HTTPOPTIONSrequests that match the given pattern.- 指定者:
OPTIONS在接口中RouterFunctions.Builder- 参数:
pattern- the pattern to match tohandlerFunction- the handler function to handle allOPTIONSrequests that matchpattern- 返回:
- this builder
-
OPTIONS
public RouterFunctions.Builder OPTIONS(String pattern, RequestPredicate predicate, HandlerFunction<ServerResponse> handlerFunction) 从接口复制的说明:RouterFunctions.BuilderAdds a route to the given handler function that handles all HTTPOPTIONSrequests that match the given pattern and predicate.- 指定者:
OPTIONS在接口中RouterFunctions.Builder- 参数:
pattern- the pattern to match topredicate- additional predicate to matchhandlerFunction- the handler function to handle allOPTIONSrequests that matchpattern- 返回:
- this builder
-
route
public RouterFunctions.Builder route(RequestPredicate predicate, HandlerFunction<ServerResponse> handlerFunction) 从接口复制的说明:RouterFunctions.BuilderAdds a route to the given handler function that handles all requests that match the given predicate.- 指定者:
route在接口中RouterFunctions.Builder- 参数:
predicate- the request predicate to matchhandlerFunction- the handler function to handle all requests that match the predicate- 返回:
- this builder
- 另请参阅:
-
resources
从接口复制的说明:RouterFunctions.BuilderRoute 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);- 指定者:
resources在接口中RouterFunctions.Builder- 参数:
pattern- the pattern to matchlocation- the location directory relative to which resources should be resolved- 返回:
- this builder
-
resources
public RouterFunctions.Builder resources(Function<ServerRequest, Optional<cn.taketoday.core.io.Resource>> lookupFunction) 从接口复制的说明:RouterFunctions.BuilderRoute 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.- 指定者:
resources在接口中RouterFunctions.Builder- 参数:
lookupFunction- the function to provide aResourcegiven theServerRequest- 返回:
- this builder
-
nest
public RouterFunctions.Builder nest(RequestPredicate predicate, Consumer<RouterFunctions.Builder> builderConsumer) 从接口复制的说明:RouterFunctions.BuilderRoute to a built 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 creates a nested route 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> nestedRoute = RouterFunctions.route() .nest(RequestPredicates.path("/user"), builder -> builder.GET(this::listUsers) .POST(this::createUser)) .build();- 指定者:
nest在接口中RouterFunctions.Builder- 参数:
predicate- the predicate to testbuilderConsumer- consumer for aBuilderthat provides the nested router function- 返回:
- this builder
- 另请参阅:
-
nest
public RouterFunctions.Builder nest(RequestPredicate predicate, Supplier<RouterFunction<ServerResponse>> routerFunctionSupplier) 从接口复制的说明:RouterFunctions.BuilderRoute to the supplied 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 creates a nested route 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> nestedRoute = RouterFunctions.route() .nest(RequestPredicates.path("/user"), () -> RouterFunctions.route() .GET(this::listUsers) .POST(this::createUser) .build()) .build();- 指定者:
nest在接口中RouterFunctions.Builder- 参数:
predicate- the predicate to testrouterFunctionSupplier- supplier for the nested router function to delegate to if the predicate applies- 返回:
- this builder
- 另请参阅:
-
path
public RouterFunctions.Builder path(String pattern, Consumer<RouterFunctions.Builder> builderConsumer) 从接口复制的说明:RouterFunctions.BuilderRoute to a built router function if the given path prefix pattern applies. This method can be used to create nested routes, where a group of routes share a common path prefix.For instance, the following example creates a nested route 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> nestedRoute = RouterFunctions.route() .path("/user", builder -> builder.GET(this::listUsers) .POST(this::createUser)) .build();- 指定者:
path在接口中RouterFunctions.Builder- 参数:
pattern- the pattern to match tobuilderConsumer- consumer for aBuilderthat provides the nested router function- 返回:
- this builder
-
path
public RouterFunctions.Builder path(String pattern, Supplier<RouterFunction<ServerResponse>> routerFunctionSupplier) 从接口复制的说明:RouterFunctions.BuilderRoute to the supplied router function if the given path prefix pattern applies. This method can be used to create nested routes, where a group of routes share a common path prefix. Specifically, this method can be used to merge externally defined router functions under a path prefix.For instance, the following example creates a nested route with a "/user" path predicate that delegates to the router function defined in
userController, and with a "/order" path that delegates toorderController.RouterFunction<ServerResponse> nestedRoute = RouterFunctions.route() .path("/user", userController::routerFunction) .path("/order", orderController::routerFunction) .build();- 指定者:
path在接口中RouterFunctions.Builder- 参数:
pattern- the pattern to match torouterFunctionSupplier- supplier for the nested router function to delegate to if the pattern matches- 返回:
- this builder
-
filter
public RouterFunctions.Builder filter(HandlerFilterFunction<ServerResponse, ServerResponse> filterFunction) 从接口复制的说明:RouterFunctions.BuilderFilters all routes created by this builder with the given filter function. Filter functions are typically used to address cross-cutting concerns, such as logging, security, etc.For instance, the following example creates a filter that returns a 401 Unauthorized response if the request does not contain the necessary authentication headers.
RouterFunction<ServerResponse> filteredRoute = RouterFunctions.route() .GET("/user", this::listUsers) .filter((request, next) -> { // check for authentication headers if (isAuthenticated(request)) { return next.handle(request); } else { return ServerResponse.status(HttpStatus.UNAUTHORIZED).build(); } }) .build();- 指定者:
filter在接口中RouterFunctions.Builder- 参数:
filterFunction- the function to filter all routes built by this builder- 返回:
- this builder
-
before
从接口复制的说明:RouterFunctions.BuilderFilter the request object for all routes created by this builder with the given request processing function. Filters are typically used to address cross-cutting concerns, such as logging, security, etc.For instance, the following example creates a filter that logs the request before the handler function executes.
RouterFunction<ServerResponse> filteredRoute = RouterFunctions.route() .GET("/user", this::listUsers) .before(request -> { log(request); return request; }) .build();- 指定者:
before在接口中RouterFunctions.Builder- 参数:
requestProcessor- a function that transforms the request- 返回:
- this builder
-
after
public RouterFunctions.Builder after(BiFunction<ServerRequest, ServerResponse, ServerResponse> responseProcessor) 从接口复制的说明:RouterFunctions.BuilderFilter the response object for all routes created by this builder with the given response processing function. Filters are typically used to address cross-cutting concerns, such as logging, security, etc.For instance, the following example creates a filter that logs the response after the handler function executes.
RouterFunction<ServerResponse> filteredRoute = RouterFunctions.route() .GET("/user", this::listUsers) .after((request, response) -> { log(response); return response; }) .build();- 指定者:
after在接口中RouterFunctions.Builder- 参数:
responseProcessor- a function that transforms the response- 返回:
- this builder
-
onError
public RouterFunctions.Builder onError(Predicate<Throwable> predicate, BiFunction<Throwable, ServerRequest, ServerResponse> responseProvider) 从接口复制的说明:RouterFunctions.BuilderFilters all exceptions that match the predicate by applying the given response provider function.For instance, the following example creates a filter that returns a 500 response status when an
IllegalStateExceptionoccurs.RouterFunction<ServerResponse> filteredRoute = RouterFunctions.route() .GET("/user", this::listUsers) .onError(e -> e instanceof IllegalStateException, (e, request) -> ServerResponse.status(HttpStatus.INTERNAL_SERVER_ERROR).build()) .build();- 指定者:
onError在接口中RouterFunctions.Builder- 参数:
predicate- the type of exception to filterresponseProvider- a function that creates a response- 返回:
- this builder
-
onError
public RouterFunctions.Builder onError(Class<? extends Throwable> exceptionType, BiFunction<Throwable, ServerRequest, ServerResponse> responseProvider) 从接口复制的说明:RouterFunctions.BuilderFilters all exceptions of the given type by applying the given response provider function.For instance, the following example creates a filter that returns a 500 response status when an
IllegalStateExceptionoccurs.RouterFunction<ServerResponse> filteredRoute = RouterFunctions.route() .GET("/user", this::listUsers) .onError(IllegalStateException.class, (e, request) -> ServerResponse.status(HttpStatus.INTERNAL_SERVER_ERROR).build()) .build();- 指定者:
onError在接口中RouterFunctions.Builder- 参数:
exceptionType- the type of exception to filterresponseProvider- a function that creates a response- 返回:
- this builder
-
withAttribute
从接口复制的说明:RouterFunctions.BuilderAdd an attribute with the given name and value to the last route built with this builder.- 指定者:
withAttribute在接口中RouterFunctions.Builder- 参数:
name- the attribute namevalue- the attribute value- 返回:
- this builder
-
withAttributes
从接口复制的说明:RouterFunctions.BuilderManipulate the attributes of the last route built with the given consumer.The map provided to the consumer is "live", so that the consumer can be used to overwrite existing attributes, remove attributes, or use any of the other
Mapmethods.- 指定者:
withAttributes在接口中RouterFunctions.Builder- 参数:
attributesConsumer- a function that consumes the attributes map- 返回:
- this builder
-
build
从接口复制的说明:RouterFunctions.BuilderBuilds theRouterFunction. All created routes are composed with one another, and filters (if any) are applied to the result.- 指定者:
build在接口中RouterFunctions.Builder- 返回:
- the built router function
-