詳解Spring mvc ant path的使用方法
詳解Spring mvc ant path的使用方法
概要:
任何一個WEB都需要解決URL與請求處理器之間的映射,spring MVC也是一樣,但Spring MVC就像Spring所作的一切一樣(靈活,可以配置各種東西,但是也造成了很多復(fù)雜性),肯定不會只有一種方法來映射URL和 Controller之間的關(guān)系,并且在實際上,允許你自己創(chuàng)建映射規(guī)則和實現(xiàn),而不僅僅依賴URL映射。
1、Spring path match
Spring MVC中的路徑匹配要比標準的web.xml要靈活的多。默認的策略實現(xiàn)了 org.springframework.util.AntPathMatcher,就像名字提示的那樣,路徑模式是使用了Apache Ant的樣式路徑,Apache Ant樣式的路徑有三種通配符匹配方法(在下面的表格中列出)這些可以組合出很多種靈活的路徑模式。
2、Apache ant type
下面就來描述一下apache ant匹配規(guī)則,其實還是挺簡單的。
Ant通配符描述
Wildcard | Description |
---|---|
? | 匹配任何單字符 |
* | 匹配0或者任意數(shù)量的字符 |
** | 匹配0或者更多的目錄 |
3、舉例說明:
1、 /views/products/**/*.cfm
# Matches /views/products/index.cfm /views/products/SE10/index.cfm /views/products/SE10/details.cfm /views/products/ST80/index.cfm /views/products/ST80/details.cfm # Does Not Match: /views/index.cfm /views/aboutUs/index.cfm /views/aboutUs/managementTeam.cfm
2、 /views/**/*.cfm
# Matches: /views/index.cfm /views/aboutUs/index.cfm /views/aboutUs/managementTeam.cfm /views/products/index.cfm /views/products/SE10/index.cfm /views/products/SE10/details.cfm /views/products/ST80/index.cfm /views/products/ST80/details.cfm # Does Not Match: /views/index.htm /views/readme.txt
3、 /views/index??.cfm
# Matches: /views/index01.cfm /views/index02.cfm /views/indexAA.cfm # Does Not Match: /views/index01.htm /views/index1.cfm /views/indexA.cfm /views/indexOther.cfm /views/anotherDir/index01.cfm
如果知道這些我們就能夠在Spring MVC靈活的配置url映射了。
如有疑問請留言或者到本站社區(qū)交流討論,感謝閱讀,希望能幫助到大家,謝謝大家對本站的支持!
相關(guān)文章
JSP 自定義標簽實現(xiàn)數(shù)據(jù)字典的實例
這篇文章主要介紹了JSP 自定義標簽實現(xiàn)數(shù)據(jù)字典的實例的相關(guān)資料,這里實現(xiàn)這樣的功能,希望能幫助到大家,需要的朋友可以參考下2017-08-08FCKeditor使用方法(FCKeditor_2.6.3)詳細使用說明
要用到文本編輯器,選擇了FCKeditor,下面就配置作一下說明: 環(huán)境:windowsXP myeclipse6.0GA fckeditor2.6.3 fckeditor2.32008-09-09將properties文件的配置設(shè)置為整個Web應(yīng)用的全局變量實現(xiàn)方法
下面小編就為大家?guī)硪黄獙roperties文件的配置設(shè)置為整個Web應(yīng)用的全局變量實現(xiàn)方法。小編覺得挺不錯的,現(xiàn)在就分享給大家,也給大家做個參考。一起跟隨小編過來看看吧2017-10-10淺談SpringMVC jsp前臺獲取參數(shù)的方式 EL表達式
下面小編就為大家分享一篇淺談SpringMVC jsp前臺獲取參數(shù)的方式 EL表達式,具有很好的參考價值,希望對大家有所幫助。一起跟隨小編過來看看吧2018-03-03