저는이 문제로 오래 동안 고심하고 있었지만 아직 해결하지 못했습니다.Thymeleaf와 Spring의 스타일 시트를 연결하는 데 문제가 있습니다.
외부 CSS 파일을 작동시킬 수 없습니다. 브라우저는 항상 200 개의 성공 메시지를 표시하지만 파일은 절대로드되지 않습니다.
나는 여러 가지 방법을 시도했지만이는 순간에 모습입니다 :
HTML 파일에 링크 :
<!DOCTYPE HTML>
<html xmlns:th="http://www.thymeleaf.org">
<head>
<title>Tourverwalter</title>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8" />
<link rel="stylesheet" type="text/css" th:href="@{/assets/css/myStyle.css}" />
</head>
CSS 파일 :
body {
background-color: lightblue;
text-align: center;
}
.button {
background-color: #4CAF50; /* Green */
border: none;
color: white;
padding: 15px 32px;
text-align: center;
text-decoration: none;
display: inline-block;
font-size: 16px;
width: 20%;
cursor: pointer;
}
header{
vertical-align: top;
}
.container {
width: 75%;
height: 30px;
padding: 10px;
}
.left {
width: 40%;
height:30px;
float: left;
}
.right {
margin-left: 60%;
height: 30px;
}
WebMcvConfig 파일 :
package ese4.configuration;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import org.springframework.security.crypto.bcrypt.BCryptPasswordEncoder;
import org.springframework.web.servlet.config.annotation.ResourceHandlerRegistry;
import org.springframework.web.servlet.config.annotation.WebMvcConfigurerAdapter;
@Configuration
public class WebMvcConfig extends WebMvcConfigurerAdapter {
@Bean
public BCryptPasswordEncoder passwordEncoder() {
BCryptPasswordEncoder bCryptPasswordEncoder = new BCryptPasswordEncoder();
return bCryptPasswordEncoder;
}
@Override
public void addResourceHandlers(ResourceHandlerRegistry registry) {
registry.addResourceHandler("/assets/**").addResourceLocations("classpath:/assets/");
}
}
,451,515,
그리고 폴더 계층 구조 :
src/main/resources/static/css
을 그리고 당신이 무시 addResourceHandlers
방법을 제거 할 수 있습니다 : 당신이 봄 부팅을 사용하는 경우 Folder Hierarchy
것은 당신이 봄 부팅을 사용하고 있습니까 :
마지막으로, 다른 방법으로 단순화 할 수있다? – bphilipnyc예 스프링 부트를 사용 중입니다. –