What is the best way to create @RequestMapping when i need to find user by id (e.g. "api.com/id5") and by nickname ("api.com/nick1")? I have problem with same pattern and Spring mapping can define "id1" as a nickname (but it is impossible because the nicknames are checked before registration). I thought that the code has to be like this:
@RequestMapping(value = "/id{id}", method = RequestMethod.GET)
public ResponseEntity<Object> getUserById(@PathParam("id") long id){
return ...;
}
@RequestMapping(value = "/{nickname}", method = RequestMethod.GET)
public ResponseEntity getUserByNickname(@PathParam("nickname") String nickname){
return ...;
}
One more solution: get just a string from uri path and manually check, is it an id or nickname. So, how to do it the right way?