Spring Web MVC: Use same request mapping for request parameter and path variable

前端 未结 3 1001
南旧
南旧 2020-12-12 19:46

Is there a way to express that my Spring Web MVC controller method should be matched either by a request handing in a ID as part of the URI path ...

@Request         


        
3条回答
  •  既然无缘
    2020-12-12 20:13

    If you still want to stick to PathVariable approach and if you are getting 400 syntactically incorrect error then follow this approach-

     @RequestMapping(method=RequestMethod.GET, value={"campaigns/{id}","campaigns"})
                             public String getCampaignDetails(Model model,
                             @PathVariable Map pathVariables) 
       {
    
         System.out.println(pathVariables.get("id"));
    
       }
    

提交回复
热议问题