In a Spring-mvc interceptor, how can I access to the handler controller method?

后端 未结 2 1782
余生分开走
余生分开走 2020-12-10 13:21

In a Spring-mvc interceptor I want to access to the handler controller method

public class CustomInterceptor implements HandlerInterceptor  {
    public bool         


        
2条回答
  •  再見小時候
    2020-12-10 13:59

    You can cast the Object handler to HandlerMethod.

    HandlerMethod method = (HandlerMethod) handler;
    

    Note however that the handler argument passed to preHandle is not always a HandlerMethod (careful with ClassCastException). HandlerMethod then has methods you can use to get annotations, etc.

提交回复
热议问题