问题描述
我正在查看一些使用RequestMapping的Spring代码:
I'm looking at some Spring code that uses a RequestMapping like so:
@RequestMapping("/foo/{bar:.+}")
这在功能上是否与以下不同?
Is this functionally any different than the following?
@RequestMapping("/foo/{bar}")
从我可以看出,RegExp总是应用于斜杠之间的段,所以两者应该是等价的(尽管可能。+可能会说非空?。
From what I can tell the RegExp is always applied to the segment between slashes, so the two should be equivalent (although maybe .+ might say "non-empty?).
我想用另一种方式来表达这个问题可能是:
I suppose another way to phrase the question might be:
Spring是 {bar}
相当于 {bar:。*}
或 {bar:。+}
?
Is Spring's {bar}
equivalent to {bar:.*}
or {bar:.+}
?
推荐答案
使用小测试验证 - 它是 @RequestMapping(/ foo / {bar:。+} )
原因是它是。*
,这意味着 / foo /
和 / foo / something
将映射到相同的请求映射方法,它不会。
Verified using a small test - it is @RequestMapping("/foo/{bar:.+}")
the reason is if it is .*
, it means that /foo/
and /foo/something
will map to the same request mapped method, which it will not.
这篇关于在Spring的RequestMapping中,{parameter:。+}与{parameter}不同的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!