详解Spring mvc ant path的使用方法
概要:
任何一个WEB都需要解决URL与请求处理器之间的映射,spring MVC也是一样,但Spring MVC就像Spring所作的一切一样(灵活,可以配置各种东西,但是也造成了很多复杂性),肯定不会只有一种方法来映射URL和 Controller之间的关系,并且在实际上,允许你自己创建映射规则和实现,而不仅仅依赖URL映射。
1、Spring path match
Spring MVC中的路径匹配要比标准的web.xml要灵活的多。默认的策略实现了 org.springframework.util.AntPathMatcher,就像名字提示的那样,路径模式是使用了Apache Ant的样式路径,Apache Ant样式的路径有三种通配符匹配方法(在下面的表格中列出)这些可以组合出很多种灵活的路径模式。
2、Apache ant type
下面就来描述一下apache ant匹配规则,其实还是挺简单的。
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映射了。
如有疑问请留言或者到本站社区交流讨论,感谢阅读,希望能帮助到大家,谢谢大家对本站的支持!
idea官方推送了2020.2.4版本的更新,那么大家最关心的问题来了,之前激活idea202...
大家好,我是狂聊君。 今天来聊一聊 Mysql 缓存池原理。 提纲附上,话不多说,直...
CKeditor,以前叫FCKeditor,已经使用过好多年了,功能自然没的说。最近升级到3....
本文转载自微信公众号「SQL数据库」,作者丶平凡世界 。转载本文请联系开发公众...
前言 项目开发中不管是前台还是后台都会遇到烦人的null,数据库表中字段允许空值...
问题:我们在做flex的开发中,如果用到别人搭建好的框架,而别人的server名称往...
在Flash Player 10.1及以上版本中,adobe新增了全局错误处理程序UncaughtErrorEv...
本文实例讲述了AJAX+Servlet实现的数据处理显示功能。分享给大家供大家参考,具...
来源:DeepenStudy 漏洞文件:js.asp % Dimoblog setoblog=newclass_sys oblog.a...
本文转载自微信公众号「SH的全栈笔记」,作者SH。转载本文请联系SH的全栈笔记公...