詳解Spring mvc ant path的使用方法
詳解Spring mvc ant path的使用方法
概要:
任何一個WEB都需要解決URL與請求處理器之間的映射,spring MVC也是一樣,但Spring MVC就像Spring所作的一切一樣(靈活,可以配置各種東西,但是也造成了很多復雜性),肯定不會只有一種方法來映射URL和 Controller之間的關系,并且在實際上,允許你自己創(chuàng)建映射規(guī)則和實現,而不僅僅依賴URL映射。
1、Spring path match
Spring MVC中的路徑匹配要比標準的web.xml要靈活的多。默認的策略實現了 org.springframework.util.AntPathMatcher,就像名字提示的那樣,路徑模式是使用了Apache Ant的樣式路徑,Apache Ant樣式的路徑有三種通配符匹配方法(在下面的表格中列出)這些可以組合出很多種靈活的路徑模式。
2、Apache ant type
下面就來描述一下apache ant匹配規(guī)則,其實還是挺簡單的。
Ant通配符描述
| Wildcard | Description |
|---|---|
| ? | 匹配任何單字符 |
| * | 匹配0或者任意數量的字符 |
| ** | 匹配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ū)交流討論,感謝閱讀,希望能幫助到大家,謝謝大家對本站的支持!
相關文章
JSP使用JDBC完成動態(tài)驗證及采用MVC完成數據查詢的方法
這篇文章主要介紹了JSP使用JDBC完成動態(tài)驗證及采用MVC完成數據查詢的方法,實例分析了JDBC連接數據庫及查詢數據庫的實現技巧,并結合MVC框架進行分析說明,需要的朋友可以參考下2015-09-09
tomcat6下jsp出現getOutputStream() has already been called for t
這篇文章主要介紹tomcat6下jsp出現getOutputStream() has already been called for this response異常的原因和解決方法,需要的朋友可以參考下。2016-06-06
Struts html:checkbox框初始默認是選中的解決方法
在使用struts標簽html:checkbox 的時候,如何讓checkbox框默認是選中的,本文提供解決方法,需要了解的朋友可以參考下2012-12-12

