【使用篇二】SpringBoot访问静态资源(4)

时间:2023-03-09 21:44:07
【使用篇二】SpringBoot访问静态资源(4)

默认的,SpringBoot会从两个地方查找静态资源:

  • classpath/static 的目录下
  • ServletContext 根目录下

一、classpath/static 的目录

在类路径下常见static目录,名称必须是static

【使用篇二】SpringBoot访问静态资源(4)

index.html

<!DOCTYPE html>
<html>
<head>
<meta charset="UTF-8">
<title>静态资源访问方式一</title>
</head>
<body>
    静态资源访问方式一<br>
    <img alt="" src="data:images/java.png"> <!-- 不用写static-->
</body>
</html>

二、ServletContext 根目录下

在src/main中添加webapp,名称必须是webapp。

【使用篇二】SpringBoot访问静态资源(4)