Springboot項目中 前端展示本地圖片
本文使用的是Springboot官方推薦的thymeleaf(一種頁面模板技術)
首先在pom文件加依賴
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-thymeleaf</artifactId>
</dependency>
-
Springboot項目中resources文件包含 templates 和static等文件夾
-
其中templates存放html界面,static存放css、js等文件
-
想要讀取圖片,在static文件下創建images文件夾,放入圖片。
-
測試時可以在瀏覽器地址欄輸入localhost:80880/images/xxx.jpg,此時網頁可以顯示即路徑正確。
-
在html界面調用時src="images/xxx.png/jpg"
此時即可成功調用。