在springboot项目中没有我们之前常规web开发的WebContent(WebApp),它只有src目录,在src/main/resources下面有两个文件夹,static和templates。spring boot默认在static目录中存放静态页面,而templates中存放动态页面
static目录
springboot通过classpath/static目录访问静态资源。注意存放静态资源的目录名称必须是static。
templates目录
在spring boot中不推荐使用jsp作为视图层技术,而是默认使用Thymeleaf来做动态页面。Templates目录这是存放基于模板引擎渲染的视图。templates无法直接访问,安全级别比静态目录高,需要通过Controller访问
静态资源存放其他位置
注:访问顺序如下,前面的静态资源不会被后面的覆盖
#properties配置静态资源访问路径
spring.resources.static-locations=classpath:/cs/,classpath:/META-INF/resources/,classpath:/resources/,classpath:/static/,classpath:/public/
#yaml配置静态资源访问路径
spring:
resources:
static-locations:
- classpath:/cs/
- classpath:/META-INF/resources/
- classpath:/resources/
- classpath:/static/
- classpath:/public/