gpt4 book ai didi

java - 使用 Spring 3 RequestMapping Annotation 匹配 "Rest of the URL"

转载 作者:太空狗 更新时间:2023-10-29 22:36:47 26 4
gpt4 key购买 nike

<分区>

Possible Duplicate:
Spring 3 RequestMapping: Get path value

在 Spring 3 中,有没有办法在以下 URL 中捕获 rest/of/the/url:

/myapp/foo/bar/rest/of/the/url

通过像这样使用@RequestMapping 注释:

@RequestMapping(value="{appname}/{path1}/{path2}/{remainder}")
public String myRequestMethod(
@PathVariable("appname") String appName,
PathVariable("path1") String path1,
PathVariable("path2") String path2,
PathVariable("remainder") String remainder)

我希望 RequestMapping 像这样匹配

{appname}   -> myapp
{path1} -> foo
{path2} -> bar
{remainder} -> rest/of/the/url

Javadocs对于 RequestMapping,有一个关于使用备用正则表达式的注释:

By default, the URI template will match against the regular expression [^.]* (i.e. any character other than period), but this can be changed by specifying another regular expression, like so: /hotels/{hotel:\d+}

但是当我像这样使用 RequestMapping 时,它的行为并不像预期的那样(我得到 404):

@RequestMapping(value="{appname}/{path1}/{path2}/{remainder:.[\\S]*}")

有谁知道如何将 URL 的其余部分与 Spring RequestMapping 相匹配?

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com