Java – use spring MVC annotation based controller and @ requestmapping to narrow the problem

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 it in my browser:

mySite.com/test.html?myParam=1

I expect an ambiguoushandlermappingexception or something because both methods seem to match the URL

But actually the first method is called Does anyone know why?

Solution

It smells like a bug If you add method = get to the second handler, it will work as expected, so this is the solution

I have submitted an error report and hope it can be solved

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

The content of this article comes from the network collection of netizens. It is used as a learning reference. The copyright belongs to the original author.
THE END
分享
二维码
< <上一篇
下一篇>>