在使用Zuul 做網(wǎng)關(guān)權(quán)限控制的時候,需要判斷當(dāng)前登陸用戶是否有權(quán)限訪問接口。這里就涉及到url路徑匹配問題。這里因為用戶權(quán)限開發(fā)過程中使用到了這方面的知識,所以系統(tǒng)學(xué)習(xí)一下。
AntPathMatcher是路徑匹配規(guī)則工具類,可以根據(jù)ant路徑匹配規(guī)則判斷給定的字符串是否匹配。
ant 匹配規(guī)則如下:
- ? 匹配一個字符(除過操作系統(tǒng)默認(rèn)的文件分隔符)
- * 匹配0個或多個字符
- **匹配0個或多個目錄
用例如下

image.png
測試用例:
public class AntPathMatcherTest {
public static void main(String[] args) {
PathMatcher pathMatcher = new AntPathMatcher();
System.out.println(pathMatcher.match("/*/retail/**", "/cir-node/retail/save")); //true
System.out.println(pathMatcher.match("*test*", "AnothertestTest")); //true
System.out.println(pathMatcher.match("/????", "/bala/bla")); //false
}
}