Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

create two method for same url pattern with different arguments

I have scenario where one url "serachUser" may come with two different value (request parameter) userId or UserName.

so for this I have created two methods

public String searchUserById(@RequestParam long userID, Model model) 
public ModelAndView searchUserByName(@RequestParam String userName)

But i am getting Ambiguous mapping found exception. Can Spring handle this situation?

like image 641
Vikas Singh Avatar asked Apr 06 '13 16:04

Vikas Singh


1 Answers

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) {
  // ...
}
like image 136
kryger Avatar answered Nov 16 '22 02:11

kryger