Spring Boot 访问静态资源


在SpringBoot 项目中没有我们之前常规web 开发的WebContent(WebApp),它只有
src 目录。在src/main/resources 下面有两个文件夹,static 和templates。SpringBoot 默认在static
目录中存放静态页面,而templates 中放动态页面。
1 static 目录
Spring Boot 通过classpath/static 目录访问静态资源。注意存放静态资源的目录名称必须
是static。
2 templates 目录
在Spring Boot 中不推荐使用jsp 作为视图层技术,而是默认使用Thymeleaf 来做动态页
面。Templates 目录这是存放Thymeleaf 的页面。

3 静态资源存放其他位置
3.1Spring Boot 访问静态资源的位置
classpath:/META‐INF/resources/
classpath:/resources/
classpath:/static/
classpath:/public/

3.2自定义静态资源位置
#配置静态资源访问路径
spring.resources.static-locations=classpath:/suibian/,classpath:/static/

posted @ 2020-05-12 10:28  郑金圣  阅读(428)  评论(0编辑  收藏  举报