我要实施路由器规则:
我怎么办?
@Bean
public RouteLocator customRouteLocator(RouteLocatorBuilder builder) {
return builder.routes()
.route(r -> r.path("/api").and().query("method").and().query("method", "login").uri("lb://bizservice-sys")
)
.build();
}
答案 0 :(得分:0)
假设您使用的是Spring Boot,这是一个代码段:
@Bean // add that bean method in a configuration class
public RouterFunction<ServerResponse> routes(MyHandler handler) {
return RouterFunctions
.route(GET("/api").and(queryParam("method", "login")), handler::login)
.andRoute(POST("/api"), handler::method);
}
@Component // create that component as a class
class MyHandler {
Mono<ServerResponse> login(ServerRequest request) {
return //...
}
Mono<ServerResponse> method(ServerRequest request) {
return //...
}
}