Spring mvc Ambiguous mapping found. Cannot map controller bean method

前端 未结 4 1951
悲&欢浪女
悲&欢浪女 2020-12-15 15:39

I am trying to build an app which can list some values from the database and modify, add, delete if necessary using Spring 4 and i receive the following error(only if the \"

4条回答
  •  鱼传尺愫
    2020-12-15 16:29

    For me adding "params" attribute in @RequestMapping worked as shown

      @ResponseBody
      @RequestMapping(method = RequestMethod.GET, params = {"id"})
      public User getUserById(final @RequestParam(name="id", required = true) String Id)
        throws InvalidArgumentException {
    
        return userService.getUserById(UUID.fromString(Id));
      }
    
      /**
       * REST service endpoint.
       * @param name Unique name for the user in the system.
       * @return Object of type {@link User} if exists otherwise null.
       */
      @ResponseBody
      @RequestMapping(method = RequestMethod.GET, params = {"name"})
      public User getUserByName(final @RequestParam(name="name", required = true) String name)
        throws InvalidArgumentException {
    
        return userService.getUserByName(name);
      }
    

    However adding both the parameters at a time in query string will give 500 error with message :

    Ambiguous handler methods mapped for HTTP path

    In that case you can have another controller method taking both params and but only uses one of them which I feel is not necessary.

提交回复
热议问题