SpringBoot訪問資源文件


一:用idea 創建 springboot 項目:

詳情請參考:《使用IDEA創建一個springboot項目

二:具體代碼內容:


1:訪問靜態資源文件

1:代碼結構

image


2:啟動項目

image


3:訪問靜態資源:圖片

image

image


4:DemoApplication

package com.alancode.springboot;

import org.springframework.boot.SpringApplication;
import org.springframework.boot.autoconfigure.SpringBootApplication;

@SpringBootApplication
public class DemoApplication {

	public static void main(String[] args) {
		SpringApplication.run(DemoApplication.class, args);
	}

}


5:訪問資源 html 文件

image

image


6:訪問靜態資源(static)文件夾的子文件夾中的資源方式

image

image

image



7:靜態資源(static)文件夾下的html文件加載 靜態資源路徑下的任意一個圖片資源

image

image






2:ServletContext 根目錄下 訪問靜態資源方式

1:代碼結構

在src/main/webapp 目錄名稱必須要 webapp

image

image


image

image

image









------------------------------


免責聲明!

本站轉載的文章為個人學習借鑒使用,本站對版權不負任何法律責任。如果侵犯了您的隱私權益,請聯系本站郵箱yoyou2525@163.com刪除。



 
粵ICP備18138465號   © 2018-2025 CODEPRJ.COM