spring AntPathRequestMatcher 工具类

/ Java / 没有评论 / 1752浏览

spring AntPathRequestMatcher 工具类

spring mvc url地址匹配工具类

AntPathRequestMatcher

在spring mvc 中我们会经常使用/**/\*.jsp/app/**/dir/file./**/example/app/*.x 类似于这样语法而负责真正判断是否匹配的工具类就是今天这篇文章主要讲解的内容AntPathRequestMatcher

Apache Ant的样式路径,有三种通配符的匹配方式

最长匹配原则(has more characters)

说明,URL请求/app/dir/file.jsp,现在存在两个路径匹配模式/**/*.jsp/app/dir/*.jsp,那么会根据模式/app/dir/*.jsp来匹配。

当然如果觉得这个工具还不够强大,还可以使用RegexRequestMatcher ,它支持使用正则表达式对URL地址进行匹配。如果你觉得这些都不够强大可以自己重写 RequestMatcher接口来进行定制的路由匹配规则。

下图这些都是已经存在的RequestMatcher接口的实现类。 2