I have two unique keys in a table: id and userId. I have to create a REST API in Spring to get user details if any of the two keys are given as path variables.
The challenge here is we have to create two different endpoints for getting user through id and getting a user through userId, but use same method for both. Also datatype of id is long and datatype of userId is String in my table.
So I am trying to do the following:
@RequestMapping(value = {"/{id}","/user/{id}"}, method=RequestMethod.GET)
public response getUser(@PathVariable("id") String id) {
}
But I am unable to figure out how to check whether I got id or userId inside the method. Also is this the right way to do it?