当前位置: 首页 > news >正文

手机 网站开发软件杭州网站推广怎样做

手机 网站开发软件,杭州网站推广怎样做,郴州买房网站,郑州管家网站托管目录 Route Predicate Factories Predicate 实现Predicate接口 测试运行 Predicate的其它实现方法 匿名内部类 lambda表达式 Predicate的其它方法 源码详解 代码示例 Route Predicate Factories The After Route Predicate Factory The Before Route Predicate Fac…

目录

Route Predicate Factories

Predicate

实现Predicate接口

测试运行

Predicate的其它实现方法

匿名内部类

lambda表达式

Predicate的其它方法

源码详解

代码示例

Route Predicate Factories

The After Route Predicate Factory

The Before Route Predicate Factory

The Between Route Predicate Factory

The Header Route Predicate Factory

The Host Route Predicate Factory

The Method Route Predicate Factory

The Path Route Predicate Factory

The RemoteAddr Route Predicate Factory


Route Predicate Factories

Predicate

Predicate是Java 8提供的⼀个函数式编程接⼝, 它接收⼀个参数并返回⼀个布尔值, ⽤于条件过滤, 请求参数的校验.

@FunctionalInterface
public interface Predicate<T> {/*** Evaluates this predicate on the given argument.** @param t the input argument* @return {@code true} if the input argument matches the predicate,* otherwise {@code false}*/boolean test(T t);
}
实现Predicate接口
package predicate;import java.util.function.Predicate;/*** 判断字符串是否为空* 空  -true* 非空 -false*/
public class StringPredicate implements Predicate<String> {@Overridepublic boolean test(String s) {return s == null || s.isEmpty();}
}
测试运行
package predicate;import org.junit.Test;import java.util.function.Predicate;public class PredicateTest {@Testpublic void test(){Predicate<String> predicate = new StringPredicate();System.out.println(predicate.test(""));System.out.println(predicate.test("aa"));}
}

运行结果:

Predicate的其它实现方法
匿名内部类
package predicate;import org.junit.Test;import java.util.function.Predicate;public class PredicateTest {    @Testpublic void test2(){Predicate<String> predicate = new Predicate<String>() {@Overridepublic boolean test(String s) {return s == null || s.isEmpty();}};System.out.println(predicate.test(""));System.out.println(predicate.test("aa"));}
}

运行结果:

lambda表达式
package predicate;import org.junit.Test;import java.util.function.Predicate;public class PredicateTest {    @Testpublic void test3(){Predicate<String> predicate = s -> s == null || s.isEmpty();System.out.println(predicate.test(""));System.out.println(predicate.test("aa"));}
}

运行结果:

Predicate的其它方法

1.isEqual(Object targetRef) :比较两个对象是否相等,参数可以为Null
2.and(Predicate other): 短路与操作,返回⼀个组成Predicate
3.or(Predicate other) :短路或操作,返回⼀个组成Predicate
4.test(T t) :传⼊⼀个Predicate参数,⽤来做判断
5.negate() : 返回表⽰此Predicate逻辑否定的Predicate

源码详解

当前类的test方法&&other类的test方法

对当前类的test方法进行取非

当前类的test方法 || other类的test方法

判断两个对象是否相等 

代码示例

代码示例1

package predicate;import org.junit.Test;import java.util.function.Predicate;public class PredicateTest {    @Testpublic void test4(){Predicate<String> predicate = s -> s == null || s.isEmpty();System.out.println(predicate.negate().test(""));System.out.println(predicate.negate().test("aa"));}
}

运行结果:

代码示例2

package predicate;import org.junit.Test;import java.util.function.Predicate;public class PredicateTest {    @Testpublic void test5(){Predicate<String> predicate = s-> "aa".equals(s);Predicate<String> predicate2 = s-> "bb".equals(s);System.out.println(predicate.or(predicate2).test(""));System.out.println(predicate.or(predicate2).test("aa"));}
}

运行结果:

代码示例3

package predicate;import org.junit.Test;import java.util.function.Predicate;public class PredicateTest {    @Testpublic void test6(){Predicate<String> predicate = s-> s!=null && !s.isEmpty();Predicate<String> predicate2 = s-> s!=null && s.chars().allMatch(Character::isDigit);System.out.println(predicate.and(predicate2).test("aa"));System.out.println(predicate.and(predicate2).test("123"));}
}

运行结果:

Route Predicate Factories

Route Predicate Factories (路由断⾔⼯⼚, 也称为路由谓词⼯⼚, 此处谓词表⽰⼀个函数), 在Spring Cloud Gateway中, Predicate提供了路由规则的匹配机制.

我们在配置⽂件中写的断⾔规则只是字符串, 这些字符串会被Route Predicate Factory读取并处理, 转变为路由判断的条件。
这个规则是由org.springframework.cloud.gateway.handler.predicate.PathRoutePredicateF
actory 来实现的.

Spring Cloud Gateway 默认提供了很多Route Predicate Factory, 这些Predicate会分别匹配HTTP请求的不同属性, 并且多个Predicate可以通过and逻辑进⾏组合.

详细介绍

The After Route Predicate Factory

The After route predicate factory takes one parameter, a datetime (which is a java ZonedDateTime). This predicate matches requests that happen after the specified datetime. The following example configures an after route predicate:

这个⼯⼚需要⼀个⽇期时间(Java的 ZonedDateTime对象), 匹配指定⽇期之后的请求

The Before Route Predicate Factory

The Before route predicate factory takes one parameter, a datetime (which is a java ZonedDateTime). This predicate matches requests that happen before the specified datetime. The following example configures a before route predicate:

匹配指定⽇期之前的请求

The Between Route Predicate Factory

The Between route predicate factory takes two parameters, datetime1 and datetime2 which are java ZonedDateTime objects. This predicate matches requests that happen after datetime1 and before datetime2. The datetime2 parameter must be after datetime1. The following example configures a between route predicate:

匹配两个指定时间之间的请求datetime2 的参数必须在datetime1 之后

The Cookie route predicate factory takes two parameters, the cookie name and a regexp (which is a Java regular expression). This predicate matches cookies that have the given name and whose values match the regular expression. The following example configures a cookie route predicate factory:

请求中包含指定Cookie, 且该Cookie值符合指定的正则表达式

The Header Route Predicate Factory

The Header route predicate factory takes two parameters, the header and a regexp (which is a Java regular expression). This predicate matches with a header that has the given name whose value matches the regular expression. The following example configures a header route predicate:

请求中包含指定Header, 且该Header值符合指定的正则表达式

The Host Route Predicate Factory

The Host route predicate factory takes one parameter: a list of host name patterns. The pattern is an Ant-style pattern with . as the separator. This predicates matches the Host header that matches the pattern. The following example configures a host route predicate:

请求必须是访问某个host(根据请求中的Host字段进⾏匹配)

The Method Route Predicate Factory

The Method Route Predicate Factory takes a methods argument which is one or more parameters: the HTTP methods to match. The following example configures a method route predicate:

匹配指定的请求⽅式

The Path Route Predicate Factory

The Path Route Predicate Factory takes two parameters: a list of Spring PathMatcher patterns and an optional flag called matchTrailingSlash (defaults to true). The following example configures a path route predicate:

匹配指定规则的路径
The RemoteAddr Route Predicate Factory

The RemoteAddr route predicate factory takes a list (min size 1) of sources, which are CIDR-notation (IPv4 or IPv6) strings, such as 192.168.0.1/16 (where 192.168.0.1 is an IP address and 16 is a subnet mask). The following example configures a RemoteAddr route predicate:

请求者的IP必须为指定范围

欢迎大家来访问我的博客主页-----》博客链接

http://www.dtcms.com/a/447428.html

相关文章:

  • 北京网站建设公司 网络服务深圳网站开发一薇
  • 康复实训室建设:全维度构建标准化康复实训教学空间,筑牢人才培养基石
  • 怎么做自己的网站赚钱模板自助建站
  • 健康实训室搭建健康技能实训的专业化核心阵地——健康实训室建设全景解读
  • 多进程编程和多线程编程的区别,应用场景
  • 曲靖企业网站建设网页设计作业10个页面
  • c++的角度上理解python
  • [创业之路-673]:创业过程个人认知与能力升级路径:与正确的人,做真确的事,用正确的方法,得到正确的结果
  • 网站制作 p雏鸟app网站推广
  • 大型游戏门户网站织梦模板芜湖网站建设
  • 网站建设淘宝jsp网站开发 心得
  • 网站 app建设开发合作协议公司换网站换域名 备案
  • 深圳建站模板公司网站对比分析
  • jsp网站开发 pdf微软雅黑做网站会涉及到侵权吗
  • 本地建站工具百度云服务器wordpress
  • 网站地图什么意思网页设计与网站开发经济可行性
  • 如何做网站导航栏的搜索引擎优化编程软件哪个好用
  • 长沙品牌网站建设重庆森林为什么不能看
  • 黄浦网站制作邯郸网站建设纵横
  • 网站建设指标中国建设企业银行app下载
  • 网站错位烟台网站设计公司
  • 哪些网站可以做团购高端创意网站建设
  • 企业网站html模板下载织梦数据库可以用到wordpress
  • 怎么知道网站的ftp兽装定制工作室
  • Python 代码执行方案学习总结
  • 佛山公司网站推广外包服务最新电大网站开发维护
  • 网站关键字统计浙江省建设诚信系统网站
  • 山东企业建站系统费用网站的网页
  • 做网站最简单wordpress为什么慢
  • 做设计的兼职网站有哪些手机装修设计软件