springboot静态资源的访问的两种情况
1.使用模板引擎thymeleaf
2.不使用模板引擎thymeleaf
一、使用模板引擎
1.引入spring-boot-starter-thymeleaf依赖
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-thymeleaf</artifactId>
<version>2.1.4.RELEASE</version>
</dependency>
2.yml配置
thymeleaf:
#热部署配置,页面不产生缓存,及时更新
cache: false
prefix: classpath:/templates
suffix: .html
encoding: UTF-8
enabled: true
目录结构如图:hello.html可以直接在接口返回处被访问到
二、不使用模板引擎
1.yml配置mvc视图解析器
spring:
mvc:
view:
#prefix: /static
suffix: .html
2.springboot默认会在static或public目录下寻找静态资源文件
目录结构如图:html文件放在public目录下,html也可以访问到
注:如果是前后端分离项目,前端直接将打包好的static文件夹和html放入public目录下即可
三、接口访问
注: 注意Controller不要写成RestController