spring:
cloud:
gateway:
routes:
- id: host_route
uri: <http://www.google.com>
predicates:
- Path=/foo/{segment},/bar/{segment}
上面路由可以匹配诸如:/foo/1 或 /foo/bar 或 /bar/baz等 其中的segment变量可以通过下面方式获取:
PathMatchInfo variables = exchange.getAttribute(URI_TEMPLATE_VARIABLES_ATTRIBUTE);
Map<String, String> uriVariables = variables.getUriVariables();
String segment = uriVariables.get("segment");