一、springboot如何引入jQuery文件
new - spring starer -设置(选择 需要的场景,web)
spring boot是一个jar,因此 静态资源就不是再存放到 webapps中, 存放在哪里?
静态资源的存放路径 通过WebMvcAutoConfiguration类-addResourceHandlers()指定:/webjars/
spring boot将静态资源存入到jar包中,引入: 从Jar目录结构的webjars开始写:http://localhost:8080/webjars/jquery/3.3.1-1/jquery.js
如何自己写 静态资源,如何放到如spring boot中? 将自己写的 静态资源->jar,同上(不推荐);
二、静态资源存放路径
推荐:spring boot约定: spring boot将一些目录结构 设置成静态资源存放目录, 我们的静态资源直接放入这些目录即可 。目录在哪里? ResourceProperties类中的CLASSPATH_RESOURCE_LOCATIONS中设置:
{
"classpath:/META-INF/resources/",
"classpath:/resources/",
"classpath:/static/",
"classpath:/public/"
}
注意:在以上目录存放资源文件后,访问时不需要加前缀,直接访问即可:http://localhost:8888/index.html
三、设置欢迎页:
1):WebMvcAutoConfiguration类中的welcomePageHandlerMapping() --> getWelcomePage()-->getIndexHtml()--> location + "index.html" ,即 任意一个静态资源目录中的 Index.html就是欢迎页
2):logo图标 favicon.ico
网站中 网页标签的Logo是固定名字 : favicon.ico
自定义 favicon.ico :阅读 源码得知 :只需要将favicon.ico文件 放入任意静态资源目录中即可。
总结:1.通过源码发现静态资源的目录
2.用静态资源:只需要将静态资源放入 以上目录即可
3. 其他特定的文件(欢迎页、ico),只需要 根据约定(index.html favicon.ico) 放入该目录即可
四、自定义静态资源目录(Properties文件中的 prefix+属性) :
spring.resources.static-locations=classpath:/res/, classpath:/img/
以上就将静态资源目录设置为了classpath:/res/, classpath:/img/ ,
注意 自定义静态资源目录后,spring boot默认的目录会失效