SpringBoot项目中没有WebApp目录,只有src目录。在src/main/resources
下面有static
和templates
两个文件夹。SpringBoot默认在static
目录中存放静态资源,而templates
中放动态页面。
static目录
SpringBoot通过/resources/static
目录访问静态资源,在resources/static
中编写html页面:
templates目录
在SpringBoot中不推荐使用JSP作为动态页面,而是默认使用Thymeleaf编写动态页面。templates目录是存放Thymeleaf页面的目录
静态资源其他存放位置
除了/resources/static
目录,SpringBoot还会扫描以下位置的静态资源:
- /resources/META‐INF/resources/
- /resources/resources/
- /resources/public/
我们还可以在配置文件自定义静态资源位置
在SpringBoot配置文件进行自定义静态资源位置配置
注意:
- 该配置会覆盖默认静态资源位置,如果还想使用之前的静态资源位置,还需要配置在后面。
- SpringBoot2.5之前的配置方式为:
spring.resources.static-locations