Spring 中的 AntPathMatcher (路径匹配器)

AntPathMatcher API

匹配符 描述 ? 匹配一个字符

  • 匹配多个字符 ** 匹配多层路径
antPathMatcher.match("/root/aaa","/root/aaa"); // true
antPathMatcher.match("/root/*",  "/root/aaa"); // true
// true,都以 / 结束
antPathMatcher.match("/root/*/", "/root/aaa/");// true
// false,结束符不一致
antPathMatcher.match("/root/*", "/root/aaa/"); // false
// true,/ 匹配 /*
antPathMatcher.match("/root/aaa/*", "/root/aaa/"); // true
// true,/ 匹配 /**
antPathMatcher.match("/root/aaa/**", "/root/aaa/"); // true
        
antPathMatcher.matchStart("/user/*","/user/001"); // 返回 true
antPathMatcher.matchStart("/user/*","/user"); // 返回 true
antPathMatcher.matchStart("/user/*","/user001"); // 返回 false
antPathMatcher.extractPathWithinPattern("uc/profile*","uc/profile.html"); // 返回 profile.html
antPathMatcher.combine("uc/*.html","uc/profile.html"); // uc/profile.html