7

このSpringMVCコントローラーについて考えてみましょう。

@Controller
@RequestMapping("/test*")
public class TestController {

  @RequestMapping(method = RequestMethod.GET)
  public void doStuff(Model model){
    ...
  }

  @RequestMapping(params = "myParam")
  public void doStuff(@RequestParam("myParam") int myParam, Model model){
    ...
  }

}

これをブラウザに入れると:

mySite.com/test.html?myParam=1

どちらのメソッドもURLと一致しているように見えるため、AmbiguousHandlerMappingExceptionなどが予想されました。

しかし、実際には最初のメソッドが呼び出されました。誰かが理由を知っていますか?

4

1 に答える 1

5

This smells like a bug. If you add method=GET to the second handler, it works as expected, so that's the workaround.

I've filed a bug report on this, hopefully it'll be addressed.

http://jira.springframework.org/browse/SPR-5772

于 2009-05-20T09:24:02.677 に答える