课程名称:Spring Cloud / Alibaba 微服务架构实战
课程章节:第7章-SpringCloud Gateway 微服务网关
课程讲师:张勤一
课程内容:
1. Spring Cloud GateWay 的核心概念
1.1 认识Spring Cloud GateWay
1.2 Spring Cloud GateWay的工作模型
1.3 Predicate 断言(谓词)的介绍
package com.imooc.ecommerce.service;
import lombok.extern.slf4j.Slf4j;
import org.junit.Test;
import org.junit.runner.RunWith;
import org.springframework.boot.test.context.SpringBootTest;
import org.springframework.test.context.junit4.SpringRunner;
import java.util.Arrays;
import java.util.List;
import java.util.function.Predicate;
@Slf4j
@SpringBootTest
@RunWith(SpringRunner.class)
public class PredicateTest {
public static List<String> MICRO_SERVICE = Arrays.asList("nacos", "authority", "gateway", "ribbon", "feign", "hystrix");
@Test
public void testPredicate_test(){
Predicate<String> letterLengthLimit = s -> s.length() > 5;
MICRO_SERVICE.stream().filter(letterLengthLimit).forEach(System.out::println);
}
@Test
public void testPredicate_and(){
Predicate<String> letterLengthLimit = s -> s.length() > 5;
Predicate<String> letterStartWith = s -> s.startsWith("gate");
MICRO_SERVICE.stream().filter(letterLengthLimit.and(letterStartWith)).forEach(System.out::println);
}
@Test
public void testPredicate_or(){
Predicate<String> letterLengthLimit = s -> s.length() > 5;
Predicate<String> letterStartWith = s -> s.startsWith("gate");
MICRO_SERVICE.stream().filter(letterLengthLimit.or(letterStartWith)).forEach(System.out::println);
}
@Test
public void testPredicate_negate(){
Predicate<String> letterLengthLimit = s -> s.startsWith("gate");
MICRO_SERVICE.stream().filter(letterLengthLimit.negate()).forEach(System.out::println);
}
@Test
public void testPredicate_isEqual(){
Predicate<String> equalsGateWay = s -> Predicate.isEqual("gateway").test(s);
MICRO_SERVICE.stream().filter(equalsGateWay).forEach(System.out::println);
}
}
视频截图:450词
打开App,阅读手记