跳到主要内容

PrefixPath 过滤器

DeepSeek V3 中英对照 PrefixPath Filter PrefixPath Filter

PrefixPath 过滤器接受一个 prefix 参数。以下示例配置了一个 PrefixPath 过滤器:

spring:
cloud:
gateway:
mvc:
routes:
- id: prefixpath_route
uri: https://example.org
filters:
- PrefixPath=/mypath
yaml
import static org.springframework.cloud.gateway.server.mvc.filter.BeforeFilterFunctions.prefixPath;
import static org.springframework.cloud.gateway.server.mvc.handler.GatewayRouterFunctions.route;
import static org.springframework.cloud.gateway.server.mvc.handler.HandlerFunctions.http;

@Configuration
class RouteConfiguration {

@Bean
public RouterFunction<ServerResponse> gatewayRouterFunctionsPrefixPath() {
return route("prefixpath_route")
.GET("/**", http("https://example.org"))
.before("/mypath")
.build();
}
}
java

这将 /mypath 前缀添加到所有匹配请求的路径中。因此,对 /hello 的请求将被发送到 /mypath/hello