Java – How to use multiple @RequestMapping annotations in spring

javaspringspring-mvc

Is it possible to use multiple @RequestMapping annotations over a method?

Like :

@RequestMapping("/")
@RequestMapping("")
@RequestMapping("/welcome")
public String welcomeHandler(){
  return "welcome";
}

Best Answer

@RequestMapping has a String[] value parameter, so you should be able to specify multiple values like this:

@RequestMapping(value={"", "/", "welcome"})