spring 通配符 匹配

    作了一個權限管理系統,須要經過通配符來過濾請求url,在網上找了半天沒有找到,後來想到spring自己就帶有這個功能,經過查詢最終找到了方法。使用該方法,須要引入spring-core包java

 

@Test
	public void regexSpringTest() {
		AntPathMatcher matcher = new AntPathMatcher();
		String path = "/test/a/b";
		String pattern = "/test/**";
		boolean isMatch=matcher.match(pattern, path);
		logger.info("isMatch:{}", isMatch);
	}

 

注意:spring

  • 加載路徑中的通配符:?(匹配單個字符),*(匹配除/外任意字符)、**/(匹配任意多個目錄)
相關文章
相關標籤/搜索