⚙️ 개발/Spring

Thymeleaf에서 html 이미지 상대경로 작성 주의

지구용사 2024. 3. 22. 16:00

웹( SpringBoot, Thymeleaf) 만들던 중 이미지를 상대경로 작성함에 있어서 엑박이 계속 뜨는 바람에 삽질을 했다.

 

작성하던 html은 templates > main에 있고 이미지는 static > img에 있었다.

그래서 당연히 templates에서 static까지 이동하기 위해 아래와 같이 작성했다.

<img class="profile-img" src="../../static/img/mainImg.png" />

 

여기서 간과한 것이 타임리프를 사용하면 resources > static 까지는 자동으로 이동한다.

따라서 static 이후 경로만 작성하면 된다.

<img class="profile-img" src="img/mainImg.png" />

 

나의 귀여운 강아지가 다시 나왔다.