gpt4 book ai didi

java - Spring中的请求映射,正则表达式作为注释中的参数

转载 作者:行者123 更新时间:2023-12-01 12:26:56 27 4
gpt4 key购买 nike

我有这样的代码:

@RequestMapping("/apple")
public void handleApple(HttpServletRequest request, HttpServletResponse response) throws IOException {
<...>
}

@RequestMapping("/test/apple")
public void handleTestApple(HttpServletRequest request, HttpServletResponse response) throws IOException {
<...>
}

是否可以将这两种方法结合在一起,但不能像:

@RequestMapping("/**/apple")
public void handleApple(HttpServletRequest request, HttpServletResponse response) throws IOException {
<...>
}

因为除了以“test”开头之外,它还允许其他 URL,这在我的情况下不适用。

最佳答案

如果只是这两个路径,并且您希望使用单个处理程序方法处理它们,只需选择其中一个方法并使用注释即可

@RequestMapping(value = {"/apple", "/test/apple"})

关于java - Spring中的请求映射,正则表达式作为注释中的参数,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/26260659/

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