gpt4 book ai didi

java - @RequestMapping 不适用于 Spring 2.5 中的类型和方法

转载 作者:行者123 更新时间:2023-11-29 03:35:20 25 4
gpt4 key购买 nike

我最近一直在阅读 Spring 3.2,现在我正在尝试使用 Spring 2.5 编写以下代码。根据我的阅读,这应该意味着它应该映射 profile/tags/me。然而事实并非如此。它只是抛出一个 No mapping found for HTTP request with URI ...。代码有什么问题,或者 Spring 2.5 的工作方式与 Spring 3 不同?

使用 Spring 2.5 时的问题

@Controller
@RequestMapping("/profile/tags")
public class ProfileController { ... }

这是 ProfileController 类中的方法:

@RequestMapping(value = "/me", method = RequestMethod.GET)    
public String show(@RequestParam final long id, final ModelMap model) { ... }

最佳答案

根据 Spring documentation ,我想你缺少接收请求参数所需的配置,如果你想接收这个请求参数:

@RequestMapping(value = "/me/{id}", method = RequestMethod.GET)    
public String show(@RequestParam("id") final long id, final ModelMap model) { ... }

或者您应该删除 RequestParam

Spring 2.5 更新

此外,由于您使用的是 Spring 2.5,因此请确保您已按预期方式配置了 DispatcherServlet;栏目 13.11 ,第 1、2 和 3 小节。总结:

  1. 应告知 DispatcherServlet 加载带注释的 RequestMappings。
  2. 应告知 DispatcherServlet 加载 Controller 注释。
  3. 不确定,但也许您需要改进用于请求映射的路径。

希望这对您有所帮助。

关于java - @RequestMapping 不适用于 Spring 2.5 中的类型和方法,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/15876834/

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