Accessing multiple controllers with same request mapping

前端 未结 3 1706
野的像风
野的像风 2020-12-16 14:12

Please find my HomeController and DemoController

class HomeController{
@RequestMapping(value=\"index\")
public void home(){
}
}

class DemoController{
@Reque         


        
3条回答
  •  误落风尘
    2020-12-16 14:59

    In Spring Web MVC this is not possible. Each mapping must be unique in your context. If not, you will receive a RuntimeException during context initialization.

    You cannot even use parameters to differentiate your endpoints because they are not evaluated while searching for a suitable handler (applicable for Servlet environments). From @RequestMapping javadoc:

    In a Servlet environment, parameter mappings are considered as restrictions that are enforced at the type level. The primary path mapping (i.e. the specified URI value) still has to uniquely identify the target handler, with parameter mappings simply expressing preconditions for invoking the handler.

    Note that you can do the opposite, so multiple URLs can point to the same handler. Have a look at Spring MVC: Mapping Multiple URLs to Same Controller

提交回复
热议问题