这是我的@RequestMapping
注解:
@RequestMapping({"/loginBadCredentials", "/loginUserDisabled", "/loginUserNumberExceeded"})
public String errorLogin(...){
...
}
方法内部错误登录,有没有办法知道这三个网址中的哪一个被“调用”?
Add HttpServletRequest
作为您的参数并使用它来查找当前请求路径。
Update:Spring还提供了RequestContextHolder
:
ServletRequestAttributes attributes = (ServletRequestAttributes) RequestContextHolder.currentRequestAttributes();
String currentReqUri = attributes.getRequest().getRequestURI();
在我看来,第一种方法更好并且更容易测试。
本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系:hwhale#tublm.com(使用前将#替换为@)