私はしばらくこのことに苦労していましたが、まだ理解できません。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/");
}
}
とフォルダ階層:
src/main/resources/static/css
そして、あなたがオーバーライドaddResourceHandlers
メソッドを削除することができます Folder Hierarchy
あなたは春のブートを使用していますか? – bphilipnyc
はい私は春のブートを使用しています –