근데 또 프로젝트 설정을 한 후 이미지 파일 하나를 보이도록 하고싶은데.
도대체 경로를 찾을 수 없었습니다.... ㅠㅠ 아... 입개발자.
-- 아래는 @EnableWebMVC를 설정하지 않았을 경우입니다.
그래서 경로와 한참을 씨름한 후 알게된 사실을 포스팅합니다.
일단 기본적으로 예전에는
webapps/WEB-INF/
를 루트로 사용했었는데, 스프링 부트의 타임리프 스타터를 사용한 후에는
<!-- thymeleaf -->
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-thymeleaf</artifactId>
</dependency>
<dependency>
<groupId>net.sourceforge.nekohtml</groupId>
<artifactId>nekohtml</artifactId>
</dependency>
src/main/resources 를 루트로
뷰 파일(.html 등)은 templates 안에
이미지, css, js 파일들은 static 안에 모아두면 절대경로처럼 사용할 수 있던것을 알게 되었습니다.
뷰 파일: src/main/resources/templates
static 파일: src/main/resources/static
그럼 이제
html에서 저 파일을 어떻게 불러오는가.
static/images/a.png 파일을 사용하려고 한다면
<img src="images/a.png"/>
<img src="/images/a.png"/>
<img th:src="@{images/a.png}"/>
<img th:src="@{/images/a.png}"/>
등 위 방법 모두 가능합니다.
아마도. ^^;
아마도 ... ? 올해 본 블로그중에 가장 무책임하고 성의없다
답글삭제