ICT/Java
Thymeleaf | css 파일 불러오기보
dazwischen
2022. 5. 18. 15:11
반응형
Java Spring Boot로 html을 다룰 때 파일로 존재하는 css 데이터를 원하는 html 문서에 불러오는 방법에 대한 글이다.
css 디렉토리 만들기
resources 디렉토리 내에 static/css 디렉토리를 만들어 준 후 css 파일을 이 폴더내에 위치 시킨다.
thymeleaf 이용해서 css 파일 불러오기
<link th:href="@{/css/main.css}" rel="stylesheet">
원하는 css 파일명을 정확히 입력하여 위와 같은 형식으로 head 내에 작성해 준다.
SecurityConfig
Spring Security (스프링 시큐리티)를 설정해 두었다면 css 파일을 문제 없이 불러 올 수 있도록 권한 설정을 추가로 해준다.
http
.csrf().disable()
.headers().frameOptions().disable()
.and()
.authorizeRequests()
.antMatchers("/", "/css/**", "/images/**", "/js/**","/h2-console/**", "/profile")
.permitAll();
}
"/css/**" 위치가 permitAll 함수를 통해 모든 사용자에게 권한이 허용 된 것을 확인 할 수 있다.
반응형