【SpringCloud框架Gateway网关常用的Route Predicate】

本笔记内容为尚硅谷SpringCloud框架开发Gateway的Predicate的使用部分

目录

1. After Route Predicate

2. Before Route Predicate

3. Between Route Predicate

4. Cookie Route Predicate

5. Header Route Predicate

6. Host Route Predicate

7. Method Route Predicate

8. Path Route Predicate

9. Query Route Predicate


1. After Route Predicate


多少时间之后访问 

【SpringCloud框架Gateway网关常用的Route Predicate】_第1张图片

 我们的问题是:上述这个After好懂,这个时间串串怎么获取

package com.atguigu.test;


import java.time.ZoneId;
import java.time.ZonedDateTime;

public class ZonedDateTimeDemo
{
    public static void main(String[] args)
    {
        ZonedDateTime zbj = ZonedDateTime.now(); // 默认时区
        System.out.println(zbj);
//        ZonedDateTime zny = ZonedDateTime.now(ZoneId.of("America/New_York")); // 用指定时区获取当前时间
//        System.out.println(zny);
    }
}

2. Before Route Predicate


多少时间之前访问 

【SpringCloud框架Gateway网关常用的Route Predicate】_第2张图片

3. Between Route Predicate


多少时间到多少时间内之间访问

4. Cookie Route Predicate


不带cookies访问

【SpringCloud框架Gateway网关常用的Route Predicate】_第3张图片

带上cookies访问

【SpringCloud框架Gateway网关常用的Route Predicate】_第4张图片

5. Header Route Predicate


两个参数:一个是属性名称和一个正则表达式,这个属性值和正则表达式匹配则执行

【SpringCloud框架Gateway网关常用的Route Predicate】_第5张图片

【SpringCloud框架Gateway网关常用的Route Predicate】_第6张图片

6. Host Route Predicate


请求域名格式 

【SpringCloud框架Gateway网关常用的Route Predicate】_第7张图片

Host Route Predicate 接收一组参数,一组匹配的域名列表,这个模板是一个 ant 分隔的模板,用.号作为分隔符。它通过参数中的主机地址作为匹配规则。

7. Method Route Predicate


请求的方式 

【SpringCloud框架Gateway网关常用的Route Predicate】_第8张图片

8. Path Route Predicate


请求路径格式 

【SpringCloud框架Gateway网关常用的Route Predicate】_第9张图片

9. Query Route Predicate


请求的参数和格式

支持传入两个参数,一个是属性名,一个为属性值,属性值可以是正则表达式。

【SpringCloud框架Gateway网关常用的Route Predicate】_第10张图片

 Predicate就是为了实现一组匹配规则,让请求过来找到对应的Route进行处理。【SpringCloud框架Gateway网关常用的Route Predicate】_第11张图片

结束!

你可能感兴趣的:(spring,cloud,gateway,spring,boot)