@Bean
public RouteLocator customRouteLocator(RouteLocatorBuilder builder) {
return builder.routes()
.route("rewritePath_route", r -> r.path("/rewritePathReq")
.uri("http://localhost:7201/gateway/rewritePathRouteResult"))
.build();
}@ResponseBody
@GetMapping("/gateway/rewritePathRouteResult")
public String rewritePathRouteResult(@RequestParam(required=false) String name) {
return "Spring Cloud Gateway RewritePath Routed Result:" + name;
}
像上面的代码,用户在浏览器请求的是:
http://localhost:7201/rewritePathReq?name=Hello
现希望能将其带着请求参数并路由为:
http://localhost:7201/gateway/rewritePathRouteResult?name=Hello
实现能在浏览器打印一句:Spring Cloud Gateway RewritePath Routed Result:Hello请问代码要怎么写呢?如果不是用GET方式,而是用POST方式,又要怎么处理呢?谢谢