HandlerMapping.PATH_WITHIN_HANDLER_MAPPING_ATTRIBUTE를 사용하여 현재 요청에 대한 URL 경로를 가져오는 간단한 예제 코드를 제공합니다.


	import org.springframework.web.bind.annotation.GetMapping;
    import org.springframework.web.bind.annotation.RequestMapping;
    import org.springframework.web.bind.annotation.RestController;
    import org.springframework.web.servlet.HandlerMapping;

    import javax.servlet.http.HttpServletRequest;

    @RestController
    @RequestMapping("/example")
    public class ExampleController {

        @GetMapping("/**")
        public String handleRequest(HttpServletRequest request) {
            String path = (String) request.getAttribute(HandlerMapping.PATH_WITHIN_HANDLER_MAPPING_ATTRIBUTE);
            return "Current request path is: " + path;
        }
    }

위 코드에서는 /example/** 경로로 들어오는 GET 요청에 대해 handleRequest 메서드를 실행합니다.

이 메서드에서는 request 객체를 통해 HandlerMapping.PATH_WITHIN_HANDLER_MAPPING_ATTRIBUTE를 가져와서 현재 요청에 대한 URL 경로를 출력하도록 구현되어 있습니다.

예를 들어, /example/test 요청이 들어온 경우에는 "Current request path is: /test" 라는 결과가 출력됩니다. 이렇게 HandlerMapping.PATH_WITHIN_HANDLER_MAPPING_ATTRIBUTE를 활용하면 스프링에서 요청에 대한 URL 경로를 쉽게 가져올 수 있습니다.