前往小程序,Get更优阅读体验!
立即前往
首页
学习
活动
专区
工具
TVP
发布
社区首页 >专栏 >Spring3属性之useDefault

Spring3属性之useDefault

作者头像
py3study
发布2020-01-08 14:47:26
3750
发布2020-01-08 14:47:26
举报
文章被收录于专栏:python3python3

今天从网上抄了个Spring MVC的demo. 发现Controller方法上采用

@RequestMapping("/hello")作为Request与Controller的映射。但对于/hello.html居然也会走这个方法。不解,调查发现在DefaultAnnotationHandlerMapping类有一个addUrlsForPath方法:

代码语言:javascript
复制
/**
     * 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来控制。

本文参与 腾讯云自媒体分享计划,分享自作者个人站点/博客。
原始发表:2019-09-13 ,如有侵权请联系 cloudcommunity@tencent.com 删除

本文分享自 作者个人站点/博客 前往查看

如有侵权,请联系 cloudcommunity@tencent.com 删除。

本文参与 腾讯云自媒体分享计划  ,欢迎热爱写作的你一起参与!

评论
登录后参与评论
0 条评论
热度
最新
推荐阅读
领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档