1.断言的官网地址:
https://docs.spring.io/spring-cloud-gateway/docs/current/reference/html/#the-after-route-predicate-factory
2.Cookie断言的使用
3.Cookie的写法说明
4.使用 curl 进行断言的测试
(1)不带Cookie访问
curl http://localhost:9527/payment/get/1
(2)带上cookie访问
curl http://localhost:9527/payment/get/2 --cookie "username=zzyy"
在application.yml中的写法:
- Cookie=username, zzyy
5.Header请求头断言的使用说明
6.使用 curl 对Header断言进行测试
(1)正确的访问
curl http://localhost:9527/payment/get/2 -H "X-Request-Id:123"
(2)错误的访问
curl http://localhost:9527/payment/get/2 -H "X-Request-Id:-1"
在application.yml中的写法:
- Header=X-Request-Id, \d+
7.Host主机断言的测试
curl http://localhost:9527/payment/get/2 -H "Host: www.atguigu.com"
application.yml中的写法:冒号后面写多个,用逗号隔开,只需要匹配到其中一个即断言匹配为真
- Host=**.atguigu.com,**.anotherhost.org
8.Query断言的测试
(1)正确的访问
curl http://localhost:9527/payment/get/2?username=33
(2)错误的访问
curl http://localhost:9527/payment/get/2?username=-31
在application.yml中的写法
- Query=username,\d+
最后,附上生成符合规范的时间的工具类
import java.time.ZonedDateTime;
public class T2
{
public static void main(String[] args)
{
ZonedDateTime zonedDateTime=ZonedDateTime.now();
System.out.println(zonedDateTime);
// 2020-04-20T09:44:34.558+08:00[Asia/Shanghai]
}
}