【问题标题】:Spring Cloud Gateway Query Predicate OR ConditionSpring Cloud Gateway 查询谓词 OR 条件
【发布时间】:2022-01-25 13:00:22
【问题描述】:

我正在开发 Spring Cloud Gateway,我想用 Query 谓词定义一个路由,当任何查询参数值匹配时,该路由应该匹配。

例如:我正在寻找单个查询谓词可以采用多个匹配值的场景。这可能吗?

- id: test-api
  uri: http://www.myhost.com
  predicates:
   - Path=/v3/test/
   - Method=POST
   - Query=key,value_1,value_2
     

Spring Cloud 文档仅谈到为 Query Predicate 匹配单个值 - https://cloud.spring.io/spring-cloud-gateway/multi/multi_gateway-request-predicates-factories.html#_query_route_predicate_factory

【问题讨论】:

    标签: spring spring-cloud-gateway


    【解决方案1】:

    我找到了指定多个查询参数匹配的方法。

    根据 spring 文档https://cloud.spring.io/spring-cloud-gateway/multi/multi_gateway-request-predicates-factories.html#_query_route_predicate_factory

    它的值是一个正则表达式字符串。因此可以通过指定由| 运算符分隔的值来完成

    - id: test-api
      uri: http://www.myhost.com
      predicates:
       - Path=/v3/test/
       - Method=POST
       - Query=key, value_1|value_2
    

    【讨论】:

      猜你喜欢
      • 2020-09-05
      • 2020-12-15
      • 2016-03-25
      • 2021-12-26
      • 1970-01-01
      • 2022-01-01
      • 1970-01-01
      • 1970-01-01
      • 2019-03-16
      相关资源
      最近更新 更多