简体   繁体   中英

Narrowing problem with Spring MVC annotation-based controller and @RequestMapping

Consider this Spring MVC Controller:

@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){
    ...
  }

}

When I put this into my browser:

mySite.com/test.html?myParam=1

I expected an AmbiguousHandlerMappingException or something, since both methods seem to match the URL.

But actually the first method got called. Does anybody know why?

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

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM