SpringMVC初学---spring3.1新特性

本文介绍Spring 3.1中URL映射的改进机制,包括RequestMappingHandlerMapping如何决定请求处理方法,以及不同URL模式的具体优先级规则。

摘要生成于 C知道 ,由 DeepSeek-R1 满血版支持, 前往体验 >

Prior to Spring 3.1, type and method-level request mappings were examined in two separate stages — acontroller was selected first by theDefaultAnnotationHandlerMappingand the actual method toinvoke was narrowed down second by theAnnotationMethodHandlerAdapter.


3.1之前,根据url映射到方法需要经过两步骤1,根据 DefaultAnnotationHandlerMapping 找到controller, 2, 根据 AnnotationMethodHandlerAdapter. 找到method


With the new support classes in Spring 3.1, theRequestMappingHandlerMappingis the only placewhere a decision is made about which method should process the request

3.1之后只有一步,RequestMappingHandlerMapping,是唯一一个地方决定哪个方法处理传过来的请求




/hotels/{hotel}/* has 1 URI variable and 1 wild card and is considered more specific than/hotels/{hotel}/**which as 1 URI variable and 2 wild cards.

拥有一个URI变量和一个*号的相比于一个URI变量2*号的更特殊


If two patterns have the same count, the one that is longer is considered more specific. For example/foo/bar* is longer and considered more specific than/foo/*.

相同的URI变量,相同的*号,长的更特殊


When two patterns have the same count and length, the pattern with fewer wild cards is consideredmore specific. For example/hotels/{hotel}is more specific than/hotels/*.


/hotels/{hotel} (特殊)

/hotels/*

相同的长度和相同的URI变量个数,*号少的特殊



• The default mapping pattern /**is less specific than any other pattern.For example/api/{a}/

{b}/{c} is more specific.

/**

/api/{a}/{b}/{c}(特殊)


• A prefix patternsuch as /public/** is less specific than any other pattern that doesn’t contain

double wildcards. For example/public/path3/{a}/{b}/{c}is more specific.

/public/path3/{a}/{b}/{c}(特殊 specific)

/public/**


For the full details seeAntPatternComparatorinAntPathMatcher




评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值