실제 URL 문자열 패턴을 얻을, 봄 요격에 요청 매핑 오브젝트를 취득

아담 카 :

이유를 설명하기 어려울 수도 있지만 나는 현재 요청 된 URL의 요청 URL 맵핑 문자열을 얻을 필요가이 문제를 가지고있다.

Like if I have a GET URL as "/Test/x/{number}" 
I want to get "/Test/x/{number}" not "/Test/x/1"

나는 인터셉터의 실제 선언 URL 문자열을받을 수 있나요?

이것이 가능하다면 어떻게 이것을 달성 할 수

대런 포사이스 :

당신은을 구현할 수 HanderInterceptor, 절편에 사전 또는 요청을 게시하고 방법의 인트로 호출되고.

public class LoggingMethodInterceptor implements HandlerInterceptor {
    Logger log = LoggerFactory.getLogger(LoggingMethodInterceptor.class);

    @Override
    public boolean preHandle(HttpServletRequest request, HttpServletResponse response, Object handler) throws Exception {

        HandlerMethod method = (HandlerMethod) handler;

        GetMapping mapping = method.getMethodAnnotation(GetMapping.class);

        log.info("URL is {}", Arrays.toString(mapping.value()));

        return true;
    }
}

이 출력됩니다, URL is [/hello/{placeholder}]

전체 예제는 여기에서 찾을 수 있습니다, https://github.com/Flaw101/spring-method-interceptor

당신의 인트로에 더 많은 로직을 추가 할 수 있습니다 특정 방법, 요청 등 등 특정 유형의

추천

출처http://43.154.161.224:23101/article/api/json?id=188234&siteId=1