• Spring源码解析


    文章摘要:

      1. ant匹配规则

      2. PathMatcher接口

      3. 通过测试用例看AntPathMatcher的使用

    ant匹配规则

    AntPathMatcher如名使用的ant 的匹配规则,我们先看看吧.

      字符wildcard    描述

       ?         匹配一个字符

       *         匹配0个及以上字符

       **         匹配0个及以上目录directories

    看几个官方的例子吧:

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

    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);
    
    }

    http://www.cnblogs.com/leftthen/p/5212221.html

  • 相关阅读:
    tp5.1 order by limit 分页时会出现数据重复,丢数据
    使用composer 出现Could not find a matching version of package xxx
    tp5.1 使用 tcpdf库 生成pdf
    Java调用FTP
    Quartz的org.quartz.jobStore.misfireThreshold属性理解
    第3章:WinDbg 内核调试
    第38章: PE32+
    第37章: x64处理器
    第36章:64位计算
    django框架
  • 原文地址:https://www.cnblogs.com/jifeng/p/5915572.html
Copyright © 2020-2023  润新知