springmvc之PathMatcher路径匹配

 PathMatcher作为一个路径匹配器,在springMVC中运用十分广泛.通过相应的url如何定位的相应的controller就需要用到PathMatcher进行匹配,当然spring中这个路径匹配规则都是

 Ant分风格。这是PathMatcher源码的内容,介绍了PathMatcher用处。

Used by {@link org.springframework.core.io.support.PathMatchingResourcePatternResolver},

{@link org.springframework.web.servlet.handler.AbstractUrlHandlerMapping},
 {@link org.springframework.web.servlet.mvc.multiaction.PropertiesMethodNameResolver},
 and {@link org.springframework.web.servlet.mvc.WebContentInterceptor}. 

ANT方式的通配符有三种:

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

PathMatcher

boolean isPattern(String path);//判断传入的path是否可以作为pattern使用

boolean match(String pattern, String path);//使用pattern匹配path

boolean matchStart(String pattern, String path);//使用pattern匹配path开始部分

String extractPathWithinPattern(String pattern, String path);//获取占位符匹配的内容

       For example: For "myroot/*.html" as pattern and "myroot/myfile.html"
      as full path, this method should return "myfile.html".

 Map<String, String> extractUriTemplateVariables(String pattern, String path);//根据路径匹配参数,也就是获取路径传参的值.

       <p>For example: For pattern "/hotels/{hotel}" and path "/hotels/1", this method will
      return a map containing "hotel"->"1".

 String combine(String pattern1, String pattern2);//Combines two patterns into a new pattern that is returned.

下面我们来重点看看PathMatcher的实现类AntPathMatcher:

 

 

 

 

       

 

 

 

 

 

 

 



转载于:https://www.cnblogs.com/caibixiang123/p/8637603.html

  • 0
    点赞
  • 2
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值