区分@ PostMapping,@ GetMapping或@RequestMapping中的不同值

时间:2017-08-14 08:55:09

标签: spring spring-mvc

@PostMapping(value = { "/weblogin", "/mobilelogin" })
@ResponseStatus(HttpStatus.OK)
public AccessTokenResponseModel login() { // need to distinguish "/weblogin" or "/mobilelogin" }

在春季启动时,如何区分邮件请求来自“/ weblogin”或“/ mobilelogin” 在login()方法?

1 个答案:

答案 0 :(得分:2)

您可以使用BEST_MATCHING_PATTERN_ATTRIBUTE属性。

@PostMapping(value = { "/weblogin", "/mobilelogin" })
@ResponseStatus(HttpStatus.OK)
public AccessTokenResponseModel login(HttpServletRequest httpRequest) {
   final String requestMapping = ( String ) httpRequest.getAttribute( HandlerMapping.BEST_MATCHING_PATTERN_ATTRIBUTE );
   final boolean isMobileLogin = requestMapping.contains("/mobilelogin");

   ....
}