2

我目前正在处理一个现有项目(java 版本:1.7.0,使用 Spring MVC 框架版本:3.1.4),我们只PathVariable在特定控制器类的一个 URI 中找到了这个问题,如果你们中的任何人都已经遇到过这个错误,你们是如何修复/解决它的?谢谢!

代码(java控制器类的提取部分):

@RequestMapping(value = "/site/apps/{question}.json", method = RequestMethod.GET)
public @ResponseBody ServiceResponse moreUsers(
        @PathVariable("question") final Question question,
        @RequestParam(value = "sort", required = false) final String sort,
        final HttpServletRequest request, final Model model)

我们的 tomcat 日志(catalina.out 文件)的错误输出:

ERROR Error executing request: /site/apps/52440.json
org.springframework.web.bind.annotation.support.HandlerMethodInvocationException: Failed to invoke handler method [public com.project.infrastructure.service.ServiceResponse com.project.plugins.controllers.SiteAppController.moreUsers(com.project.models.node.Question,java.lang.String,javax.servlet.http.HttpServletRequest,org.springframework.ui.Model)]; nested exception is java.lang.IllegalStateException: **Could not find @PathVariable [question] in @RequestMapping**

我们已经研究过的内容:

4

1 回答 1

0

在您的方法处理程序中尝试使用 {question} pathVariable 作为 int,假设您的 Question JavaBean 中有 int questionid 字段并尝试在方法处理程序中构造 Question JavaBean ..

@RequestMapping(value = "/site/apps/{question}.json", method = RequestMethod.GET)
public @ResponseBody ServiceResponse moreUsers(
        @PathVariable("question") Integer question,
        @RequestParam(value = "sort", required = false) final String sort,
        final HttpServletRequest request, final Model model){

Question Q=questionservice.getQuestion(question);

}
于 2016-06-21T11:56:52.337 回答