【SpringBoot】06.SpringBoot访问静态资源

SpringBoot访问静态资源

1.SpringBoot从classpath/static的目录

目录名称必须是static
1551952161635.png

启动项目,访问http://localhost:8080/0101.jpg
可以访问!
也可以在static中建立别的文件夹,例如:images ,访问的时候需要加上路径:http://localhost:8080/images/xxx.jpg 也可以。
如果想要在html页面中访问静态资源(比如图片),那么只需要填写相对路径即可例如:

<!DOCTYPE html>
<html>
<head>
<meta charset="UTF-8">
<title>静态资源方式一</title>
</head>
<body>
Hello
	<img alt="" src="0101.jpg">
</body>
</html>

2.ServletContext根目录

对于maven项目来讲,ServletContext根目录就是src/main下的webapp目录,且目录名称必须是webapp
1551953807483.png

启动项目,访问http://localhost:8080/0101.jpg
可以访问!

原文地址:https://www.cnblogs.com/isdxh/p/13528147.html