Spring Boot 访问静态资源
在 SpringBoot 项目中没有我们之前常规 web 开发的WebContent(WebApp),它只有 src 目录。在 src/main/resources 下面有两个文件夹,static 和 templates。
SpringBoot 默认在 static 目录中存放静态页面,而 templates 中放动态页面。
1 static 目录
Spring Boot 通过 classpath/static 目录访问静态资源。注意存放静态资源的目录名称必须是 static。
- 将静态资源放在此目录下,通过浏览器直接可以访问
- 也可以通过Controller访问