事情來源:我自己從頭寫springboot,到了控制類發現接不上靜態資源!
找了很久,最后發現,只需要換依賴版本,讓spring-boot-starter-thymeleaf和spring-boot-dependencies對應即可!
<properties>
<spring-boot>2.6.1</spring-boot>
</properties>
<!--springboot使用spring data jpa 為止所添加的依賴-->
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-dependencies</artifactId>
<version>${spring-boot}</version>
<type>pom</type>
<scope>provided</scope>
</dependency>
<!-- https://mvnrepository.com/artifact/org.springframework.boot/spring-boot-starter-thymeleaf -->
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-thymeleaf</artifactId>
<version>${spring-boot}</version>
</dependency>
結果就可以了: