Spring里的Ant Pattern


Spring里的Ant Pattern用於匹配URL

可以參考官網:https://docs.spring.io/spring/docs/current/javadoc-api/org/springframework/util/AntPathMatcher.html

規則很簡單

? 匹配單個字符
* 匹配0個或者多個字符
** 匹配0個或多個路徑(也就是用/分割的多級路徑) 
{spring:[a-z]+} 按照正則匹配[a-z]+,並且將其作為路徑變量,變量名為"spring"

舉例

com/t?st.jsp — matches com/test.jsp but also com/tast.jsp or com/txst.jsp
com/*.jsp — matches all .jsp files in the com directory
com/**/test.jsp — matches all test.jsp files underneath the com path
org/springframework/**/*.jsp — matches all .jsp files underneath the org/springframework path
org/**/servlet/bla.jsp — matches org/springframework/servlet/bla.jsp but also org/springframework/testing/servlet/bla.jsp and org/servlet/bla.jsp
com/{filename:\\w+}.jsp will match com/test.jsp and assign the value test to the filename variable

 


免責聲明!

本站轉載的文章為個人學習借鑒使用,本站對版權不負任何法律責任。如果侵犯了您的隱私權益,請聯系本站郵箱yoyou2525@163.com刪除。



 
粵ICP備18138465號   © 2018-2025 CODEPRJ.COM