项目依赖无配置freemarker模板
假设建立的Springboot项目通过Spring boot Initializer建立的项目,用maven进行依赖包管理和构建。 在项目的.pom文件中没有下述依赖的情况下,
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-freemarker</artifactId>
</dependency>
启动Springboot项目后, 我们可以在浏览器中输入网址:http://localhost:8080就可以访问到位于项目的文件夹resources或resources/static下的index.html. 如果想访问位于resources/static/html文件夹下的静态页面xxx.html,就需要通过地址:http://localhost:8080/html/xxx.html才可以访问到。
项目依赖配置了freemarker模板
如果在项目的.pom文件中添加了下述依赖:
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-freemarker</artifactId>
</dependency>
此时在浏览器中访问html页面等静态资源,需在项目的配置文件application.yml中添加如下配置:
spring:
resources:
static-locations: classpath:/META-INF/resources/, classpath:/resources/static/, classpath:/static/, classpath:/public
才可以访问到这些静态资源。比如:在浏览器中输入http://localhost:8080就依然可以访问到位于项目的文件夹resources或resources/static下的index.html.