0

In Spring MVC i have

@RequestMapping({ "foo", "bar" })
public String method() {...

This method works with mappings "foo" or "bar". How to know in a method which one of two mappings worked? Like:

System.out.println("Your mapping is" + mapping)

gets me

Your mapping is bar

@PathVariable is unsuitable. Or maybe set restrictions on the possible values? How I can do it?

naiad09
  • 117
  • 1
  • 6

1 Answers1

0

You can use RequestContextHolder for this in your parameters:

@RequestMapping({ "foo", "bar" })
public void method(RequestContextHolder rqh) {

    ServletRequestAttributes attr = (ServletRequestAttributes) RequestContextHolder.currentRequestAttributes();
    String currentReqUri = attr.getRequest().getRequestURI();

    System.out.println("Your mapping is" + currentReqUri)
}
Roel Strolenberg
  • 2,922
  • 1
  • 15
  • 29