目录
一.静态资源相关目录
二.静态资源其他存放位置
三.SpringBoot整合JSP
一.静态资源相关目录
SpringBoot
项目中没有
WebApp
目录,只有
src
目录。在
src/main/resources
下面有
static
和
templates
两个文件夹。
SpringBoot
默认在
static
目录中存放静态资源,而
templates
中放动态页面。
static
目录
SpringBoot
通过
/resources/static
目录访问静态资源,在
resources/static
中编写html
页面:
page1.html
我的HTML
目录结构:
启动i项目,static和templates都是根目录,所以直接访问localhost:8080/page1.html,
templates目录
在
SpringBoot
中不推荐使用
JSP
作为动态页面,而是默认使用Thymeleaf编写动态页面。
templates
目录是存放
Thymeleaf
页面的目录,后面我们讲解Thymeleaf
技术。
二.静态资源其他存放位置
除了
/resources/static
目录,
SpringBoot
还会扫描以下位置的静态资源:
以下
META‐INF,resources,publicu(
这三个也是根目录
)需要的话自己创建即可
/resources/META‐INF/resources/ /resources/resources/ /resources/public/
访问下面的地址都可以访问到html页面
localhost:8080/page2.html
localhost:8080/page3.html
localhost:8080/page4.html
我们还可以在配置文件自定义静态资源位置
在
SpringBoot
配置文件(比如application.yml)进行自定义静态资源位置配置,因为咱们自己定义的suibian文件不是默认的路径,所以我们需要进行配置
spring:
web:
resources:
static-locations: classpath:/suibian/,classpath:/public/
如果只配置classpath:/suibian/的话,那么page3.html就访问不到了,所以想问谁就得加谁的路径!
三.SpringBoot整合JSP
在
SpringBoot
中不推荐使用
JSP
作为动态页面,我们要想使用
JSP
编写动态页面,需要手动添加webapp
目录。
既然不推荐,那这里就跳过了,如果能用到再来学。
好文链接
发表评论