springboot中不应该直接访问templates下的html文件,应该从服务器端跳转。
1.添加依赖(创建springboot项目时如果勾选了模板引擎,此步跳过)
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-thymeleaf</artifactId>
</dependency>
2.在application.properties文件中添加前缀(缓存会影响界面实时显示)
#使用SpringBoot会使html页面存在缓存问题,所以在此处禁用SpringBoot的缓存
spring.thymeleaf.cache=false
spring.thymeleaf.prefix=classpath:/templates/
在访问/index时就会跳转到index.html界面