初次接觸SpringBoot后你一定會有所困惑,原來的webapp哪去了帅涂?
我該怎么訪問我的靜態(tài)文件呢议薪?
首先你要搭建起來一個基本的springBoot工程,這里就不說了媳友。
首先你要在你pom文件中加入:
<dependency>
????<groupId>org.springframework.boot</groupId>
????<artifactId>spring-boot-starter-thymeleaf</artifactId>
</dependency>
在配置文件中增加以下配置信息:
## 檢查模板是否存在斯议,然后再呈現(xiàn)
spring.thymeleaf.check-template-location=true
#Content-Type值
spring.thymeleaf.content-type=text/html
#啟用MVC Thymeleaf視圖分辨率
spring.thymeleaf.enabled=true
## 應(yīng)該從解決方案中排除的視圖名稱的逗號分隔列表
##spring.thymeleaf.excluded-view-names=
#模板編碼
spring.thymeleaf.mode=LEGACYHTML5
# 在構(gòu)建URL時預先查看名稱的前綴
spring.thymeleaf.prefix=classpath:/templates/
# 構(gòu)建URL時附加查看名稱的后綴.
spring.thymeleaf.suffix=.html
# 鏈中模板解析器的順序
#spring.thymeleaf.template-resolver-order= o
# 可以解析的視圖名稱的逗號分隔列表
#spring.thymeleaf.view-names=
#thymeleaf end
#配置靜態(tài)資源路徑
spring.resources.static-locations=classpath:/static/
需要注意的是
Springboot中默認的靜態(tài)資源路徑有:
classpath:/META-INF/resources/,classpath:/resources/庆锦,classpath:/static/捅位,classpath:/public/,
從這里可以看出這里的靜態(tài)資源路徑都是在classpath中