List<String> list = List.of("aaa_1.csv", "aaa_2.csv", "aaa_3.csv", "aaa_1.xlsx", "aaa", "aaa.pdf"); Stringpattern1="a*.csv";
System.out.println("by antPathMatcher.."); for (String s : list) { System.out.printf("pattern %s match %s is %s %n", pattern1,s, antPathMatcher.match(pattern1,s)); } System.out.println("by patternParser.."); for (String s : list) { System.out.printf("pattern %s match %s is %s %n", pattern1,s, patternParser.parse(pattern1).matches(PathContainer.parsePath(s))); } } }
// 结果 // by antPathMatcher.. // pattern a*.csv match aaa_1.csv is true // pattern a*.csv match aaa_2.csv is true // pattern a*.csv match aaa_3.csv is true // pattern a*.csv match aaa_1.xlsx is false // pattern a*.csv match aaa is false // pattern a*.csv match aaa.pdf is false // by patternParser.. // pattern a*.csv match aaa_1.csv is true // pattern a*.csv match aaa_2.csv is true // pattern a*.csv match aaa_3.csv is true // pattern a*.csv match aaa_1.xlsx is false // pattern a*.csv match aaa is false // pattern a*.csv match aaa.pdf is false
Stringpattern="/api/hancher/{*spring}"; List<String> list = List.of("/api/hancher/a/b/c", "/api/hancher/a", "/api/hancher/a/", "/api/hancher/a/b/c.csv","/api/test/a/b/c");
for (String s : list) { System.out.printf("pattern %s match %s is %s %n", pattern,s, patternParser.parse(pattern).matches(PathContainer.parsePath(s))); System.out.printf("pattern %s match %s result %s %n", pattern,s, patternParser.parse(pattern).matchAndExtract(PathContainer.parsePath(s))); } } }
// 结果 //pattern /api/hancher/{*spring} match /api/hancher/a/b/c is true //pattern /api/hancher/{*spring} match /api/hancher/a/b/c result PathMatchInfo[uriVariables={spring=/a/b/c}, matrixVariables={}] //pattern /api/hancher/{*spring} match /api/hancher/a is true //pattern /api/hancher/{*spring} match /api/hancher/a result PathMatchInfo[uriVariables={spring=/a}, matrixVariables={}] //pattern /api/hancher/{*spring} match /api/hancher/a/ is true //pattern /api/hancher/{*spring} match /api/hancher/a/ result PathMatchInfo[uriVariables={spring=/a/}, matrixVariables={}] //pattern /api/hancher/{*spring} match /api/hancher/a/b/c.csv is true //pattern /api/hancher/{*spring} match /api/hancher/a/b/c.csv result PathMatchInfo[uriVariables={spring=/a/b/c.csv}, matrixVariables={}] //pattern /api/hancher/{*spring} match /api/test/a/b/c is false //pattern /api/hancher/{*spring} match /api/test/a/b/c result null