spring AntPathRequestMatcher 工具类

spring mvc url地址匹配工具类

AntPathRequestMatcher

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

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

  • ?(匹配任何单字符)
  • *(匹配0或者任意数量的字符)
  • **(匹配0或者更多的目录)
file

最长匹配原则(has more characters)

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

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

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

file

https://www.aliyun.com/1111/2019/group-buying-share?ptCode=6417B38A34EDECB6BA258C11AE7D1879647C88CF896EF535&share_source=copy_link

你可能感兴趣的:(spring AntPathRequestMatcher 工具类)