Caused by: java.lang.IllegalStateException: Ambiguous mapping found. Cannot map 'appController' bean method

前端 未结 7 1203
感情败类
感情败类 2021-02-05 10:04

Good morning all, i\'m dealing with an Ambiguous mapping i cannot decode... I\'m using Spring mvc 4.0.6 and hibernate 4.3.6 I\'m getting this error while launching the war in to

7条回答
  •  慢半拍i
    慢半拍i (楼主)
    2021-02-05 10:16

    This is the error message you are getting:

    Ambiguous mapping found. Cannot map 'appController' bean method public java.lang.String it.besmart.controller.AppController.newClient(org.springframework.ui.ModelMap) to {[//new],methods=[POST],params=[],headers=[],consumes=[],produces=[],custom=[]}: There is already 'appController' bean method public java.lang.String it.besmart.controller.AppController.saveClient(it.besmart.models.Client,org.springframework.validation.BindingResult,org.springframework.ui.ModelMap) mapped.

    It's telling you you're mapping more than one method to handle a POST to the URL /new. If the web browser makes a POST request to the URL /new, which of your methods should handle it?

    Here are the two offending methods:

        @RequestMapping(value = {"/new"}, method = RequestMethod.POST)
        public String newClient(ModelMap model){
            Client client = new Client();
            model.addAttribute("client", client);
            model.addAttribute("edit", false);
            return "registration";
    
        }
    
        @RequestMapping(value = {"/new"}, method = RequestMethod.POST)
        public String saveClient(@Valid Client client, BindingResult result, ModelMap model){
            if(result.hasErrors()){
                return "registration";
            }
    
    
            clientService.saveClient(client);
            model.addAttribute("success", "Client" + client.getNomeClient() + "registrato correttamente");
    
            return "success";
    
        }
    

    I suspect that the first of these is incorrect; you probably want to use RequestMethod.GET instead of RequestMethod.POST for that.

提交回复
热议问题