AntPathMatcher使用

ant匹配规则

规则:

字符wildcard       描述

   ?         匹配一个字符

   *         匹配0个或者多个字符

   **         匹配0个或者多个目录

官方示例:

1、com/t?st.jsp                      
	匹配: com/test.jsp  ,  com/tast.jsp  ,  com/txst.jsp
	
2、com/*.jsp                         
	匹配: com文件夹下的全部.jsp文件
	
3、com/**/test.jsp                   
	匹配: com文件夹和子文件夹下的全部.jsp文件,
	
4、org/springframework/**/*.jsp      
	匹配: org/springframework文件夹和子文件夹下的全部.jsp文件
	
5、org/**/servlet/bla.jsp            
	匹配: org/springframework/servlet/bla.jsp,
		 org/springframework/testing/servlet/bla.jsp,
		 org/servlet/bla.jsp

PathMatcher接口方法讲解(AntPathMatcher实现PathMatcher接口)

说明:主要是判断是否匹配pattern,并解析出path中的参数

package org.springframework.util;

public interface PathMatcher {

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

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

    /**
     * 如名,是否开始部分匹配
     */
    boolean matchStart(String pattern, String path);

    /**
     * 提取path中匹配到的部分,如pattern(myroot/*.html),path(myroot/myfile.html),返回myfile.html
     */
    String extractPathWithinPattern(String pattern, String path);

    /**
     * 提取path中匹配到的部分,只是这边还需跟占位符配对为map,
     * 如pattern(/hotels/{hotel}),path(/hotels/1),解析出"hotel"->"1"
     */
    Map<String, String> extractUriTemplateVariables(String pattern, String path);

    /**
     * 提供比较器
     */
    Comparator<String> getPatternComparator(String path);

    /**
     * 合并pattern,pattern1然后pattern2
     */
    String combine(String pattern1, String pattern2);

}

URL首次匹配成功,将不再向下匹配,目前发现Shiro是这样

filterChainDefinitionMap.put("/**", "user,kickout,onlineSession,syncOnlineSession");
filterChainDefinitionMap.put("/login", "anon,captchaValidate");

比如上面的代码,由于/**在前面,用于匹配所有路径,根据以上原则,所以后面的/login永远也不会被匹配到了

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值