一、SpringBoot官方推荐使用Thymeleaf模板引擎,默认都是使用Thymeleaf模板引擎的,看自己是否导入了Thymeleaf依赖,没有导入Thymeleaf依赖,也会报404错误
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-thymeleaf</artifactId>
</dependency>
二、用Thymeleaf模板的th:…引入静态资源,网页无法加载样式:
使用该模板记得在配置文件中配置:
#thymeleaf 模版前缀,默认值,可选项
spring.thymeleaf.prefix=classpath:/templates/
#thymeleaf 模版后缀,默认值,可选项
spring.thymeleaf.suffix=.html
ing.thymeleaf.cache=false
spring.thymeleaf.encoding=utf-8
我这里没有显示是因为最初只配置了数据库【红框部分】,没有配置Thymeleaf,配置好Thymeleaf之后就可以成功加载出js和css,显示好看的页面了