在Spring的RequestMapping中,{parameter:。+}与{parameter}不同 [英] In Spring's RequestMapping, is {parameter:.+} any different than {parameter}

查看:111
本文介绍了在Spring的RequestMapping中,{parameter:。+}与{parameter}不同的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在查看一些使用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}不同的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆