zoukankan      html  css  js  c++  java
  • 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

  • 相关阅读:
    Java中的Graphics2D类基本使用教程
    JSP中页面向Action传递参数的几种方式
    中英文统计
    numpy数据集练习 ----------sklearn类
    IDEA在jsp页面写out.print()代码报错
    Tag文件的创建与应用
    Intellij部署Tomcat问题
    单例测试模式中【饿汉式】与【懒汉式】的区别
    java中类与方法叙述正确的是
    下列关于异常处理的描述中,错误的是()。
  • 原文地址:https://www.cnblogs.com/jifeng/p/5915572.html
Copyright © 2011-2022 走看看