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 \"
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.