August 14, 2021

How to get the Path Variables from a URL inside a Spring interceptor

How to get the Path Variables in URL inside a Spring interceptor


  •              Assume the URI is http://javabelazy/status/{statusId} and our interceptor is registered for this URI.
  •               This map would then be a map of a elements,with keys 'statusId ' 
              

public class JWTInterceptor extends HandlerInterceptorAdapter{
    @Override
  public boolean preHandle(final HttpServletRequest request, final HttpServletResponse response, final Object handler)
  throws Exception
  {

    final Map<String, String> pathVariables = (Map<String, String>) request
                                                                    .getAttribute(HandlerMapping.URI_TEMPLATE_VARIABLES_ATTRIBUTE);
            
               
               final Integer status = Integer.valueOf(pathVariables.get("statusId"));
               
            
  }
}


No comments:

Post a Comment

Your feedback may help others !!!

Facebook comments