Spring
Controller의 상대경로, 절대 경로
leek94
2024. 9. 23. 10:38
1. 절대 경로
절대 경로는 항상 웹 애플리케이션의 루트 경로에서 시작합니다. URL 앞에 /가 붙기 때문에, 브라우저는 현재 위치와 상관없이 루트에서부터 경로를 계산합니다.
예시:
- 현재 URL: http://example.com/products
- 절대 경로로 이동: /say-hello
<a href="/say-hello">Go to Say Hello</a>
위 링크는 현재 위치에 상관없이 http://example.com/say-hello로 이동합니다. 경로 앞에 /가 붙었으므로, 항상 루트부터 경로가 계산됩니다.
2. 상대 경로
상대 경로는 현재 페이지의 경로를 기준으로 계산됩니다. 브라우저는 현재 위치를 기준으로 경로를 해석합니다.
예시:
- 현재 URL: http://example.com/products
- 상대 경로로 이동: say-hello
<a href="say-hello">Go to Say Hello</a>
이 경우, 브라우저는 현재 URL(http://example.com/products)을 기준으로 상대 경로를 처리합니다. 그래서 최종적으로 브라우저는 http://example.com/products/say-hello로 이동합니다.
차이점 요약:
- 절대 경로 (/say-hello): 루트 경로(http://example.com/say-hello)로 이동합니다.
- 상대 경로 (say-hello): 현재 경로(http://example.com/products/say-hello)에서 이어지는 경로로 이동합니다.
상황에 따른 차이
- 현재 경로가 /products일 때:
- 절대 경로 /say-hello → http://example.com/say-hello
- 상대 경로 say-hello → http://example.com/products/say-hello
- 현재 경로가 /about일 때:
- 절대 경로 /say-hello → http://example.com/say-hello
- 상대 경로 say-hello → http://example.com/about/say-hello
이처럼, 상대 경로는 현재 URL에 따라 동적으로 변하지만, 절대 경로는 항상 루트 경로를 기준으로 동일합니다.