在Spring MVC中我有
@RequestMapping({ "foo", "bar" })
public String method() {...
此方法适用于映射" foo"或" bar"。 如何知道两个映射中哪一个有效?像:
System.out.println("Your mapping is" + mapping)
让我
Your mapping is bar
@PathVariable
不合适。或者可能对可能的值设置限制?我怎么能这样做?
答案 0 :(得分:0)
您可以在参数中使用RequestContextHolder
:
@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)
}