发布时间:2019-09-13 09:31:32编辑:auto阅读(2389)
今天从网上抄了个Spring MVC的demo. 发现Controller方法上采用
@RequestMapping("/hello")作为Request与Controller的映射。但对于/hello.html居然也会走这个方法。不解,调查发现在DefaultAnnotationHandlerMapping类有一个addUrlsForPath方法:
/**
* Add URLs and/or URL patterns for the given path.
* @param urls the Set of URLs for the current bean
* @param path the currently introspected path
*/
protected void addUrlsForPath(Set<String> urls, String path) {
urls.add(path);
if (this.useDefaultSuffixPattern && path.indexOf('.') == -1 && !path.endsWith("/")) {
urls.add(path + ".*");
urls.add(path + "/");
}
}从代码中可以看出类似/hello这种,没有点又非“/”的结尾的URL,会衍生为三个URL:
1. /hello 2. /hello.* 3. /hello/
即只要是这三种URL模式的请求,都会映射到这个Controller上。该功能的启用与停止,由属性useDefaultSuffixPattern来控制。
上一篇: nmealib解析-----(3)---
下一篇: Cisco SNMP V3 配置
51323
50779
41370
38176
32661
29551
28392
23269
23237
21562
1641°
2373°
1978°
1918°
2247°
1953°
2647°
4438°
4275°
3045°