2

私は現在、既存のプロジェクト (Java バージョン: 1.7.0、Spring MVC フレームワーク バージョン: 3.1.4 を使用) に取り組んでおりPathVariable、特定のコントローラー クラスの 1 つの 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 として使用してみてください。質問 JavaBean に int questionid フィールドがあり、メソッドハンドラー内で質問 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 に答える