gpt4 book ai didi

java - Controller 上的 Spring @RequestMapping

转载 作者:塔克拉玛干 更新时间:2023-11-02 20:06:42 31 4
gpt4 key购买 nike

我正在使用 Spring MVC 3.1.3。

我想做与 documentation 中显示的示例相同的操作. Controller 上的 @RequestMapping 和“root”方法。

但是Spring没有正确处理。

这是我的代码:

@Controller
@RequestMapping("/test")
public class TestController {
@RequestMapping(method = RequestMethod.GET)
@ResponseBody
public String list() {
return "test";
}
}

当我尝试 http://localhost/test-project/test 时,我得到一个 404 Not Found 但当我使用 http://localhost/test-project/test 时它正在工作/

有谁知道我该如何解决这个问题?

谢谢,

烟熏

编辑:

这是日志:

16:13:36,085 | DEBUG | RequestMappingHandlerMapping:209 | Looking up handler method for path /test
16:13:36,087 | DEBUG | RequestMappingHandlerMapping:219 | Did not find handler method for [/test]

最佳答案

将方法上的方法 requestMapping 标记更改为...

@RequestMapping(value = {"", "/", "/list"}, method = RequestMethod.GET)

编辑评论中的添加:

您是否尝试过将 Controller 设置为 @RequestMapping("/test*")

关于java - Controller 上的 Spring @RequestMapping,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/20522679/

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