src/main/java:主程序入口 Application,可以通过直接运行该类来 启动 Spring Boot应用
src/main/resources:配置目录,该目录用来存放应用的一些配置信息,比如应用名、服务端口、数据库配置等。由于我们应用了Web模块,因此产生了 static目录与templates目录,前者用于存放静态资源,如图片、CSS、JavaScript等;后者用于存放Web页面的模板文件。
src/test:单元测试目录,生成的 ApplicationTests 通过 JUnit4实现,可以直接用运行 Spring Boot应用的测试。
application.properties/application.yml 用于存放程序的各种依赖模块的配置信息,比如 服务端口,数据库连接配置等。。。
maven指定jdk路径、对于 静态文件的加载顺序,我们可以看官方文档的说明:
https://docs.spring.io/spring-boot/docs/current/reference/html/boot-features-developing-web-applications.html#boot-features-spring-mvc-static-content
By default, Spring Boot serves static content from a directory called /static
(or /public or /resources or /META-INF/resources) in the classpath or from the
root of the ServletContext.
这里说的是 默认情况下,Spring Boot 的静态文件加载顺序是
META/resources > resources > static > public 里面找是否存在相应的资源,
如果有则直接返回。
接下来,我们用代码做一下测试,验证 Spring Boot 静态文件加载顺序
1. 在 src/main/resources 目录下创建 public, static,templates 文件夹
<!DOCTYPE html>
<html lang="en">
<head><meta charset="UTF-8"><title>Title</title><script>window.onload = function (ev) {alert('public');}</script>
</head>
<body></body>
</html>
版权声明:本站所有资料均为网友推荐收集整理而来,仅供学习和研究交流使用。
工作时间:8:00-18:00
客服电话
电子邮件
admin@qq.com
扫码二维码
获取最新动态