score:229

Accepted answer

You can use the params parameter to filter by HTTP parameters. In your case it would be something like:

@RequestMapping(value = "/searchUser", params = "userID")
public String searchUserById(@RequestParam long userID, Model model) {
  // ...
}

@RequestMapping(value = "/searchUser", params = "userName")
public ModelAndView searchUserByName(@RequestParam String userName) {
  // ...
}

score:0

Any way incase of request param null is allowed if you don't pass any value it will be null then you can write your coad like:

@RequestMapping(value = "/searchUser", params = {"userID","userName"})
public String searchUserById(@RequestParam long userID,@RequestParam String 
userName, 
Model model) {    
if(userID != null){
//..
}else{
// ...
}

Related Query

More Query from same tag