一:用idea 创建 springboot 项目:

详情请参考:《使用IDEA创建一个springboot项目

二:具体代码内容:


1:访问静态资源文件

1:代码结构

SpringBoot访问资源文件


2:启动项目

SpringBoot访问资源文件


3:访问静态资源:图片

SpringBoot访问资源文件

SpringBoot访问资源文件


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 文件

SpringBoot访问资源文件

SpringBoot访问资源文件


6:访问静态资源(static)文件夹的子文件夹中的资源方式

SpringBoot访问资源文件

SpringBoot访问资源文件

SpringBoot访问资源文件



7:静态资源(static)文件夹下的html文件加载 静态资源路径下的任意一个图片资源

SpringBoot访问资源文件

SpringBoot访问资源文件






2:ServletContext 根目录下 访问静态资源方式

1:代码结构

在src/main/webapp 目录名称必须要 webapp

SpringBoot访问资源文件

SpringBoot访问资源文件


SpringBoot访问资源文件

SpringBoot访问资源文件

SpringBoot访问资源文件









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

相关文章: