Springboot为项目引入静态资源并访问

1、通过webjars的方式引入
访问其官网:https://www.webjars.org/
找到对应需要引入的静态资源:bootstrap、Jquery等,选择maven方式,把相应配置文件复制到我们项目的pom.xml文件中。
在这里插入图片描述
访问的时候如:http://localhost/webjars/jquery/3.3.1/jquery.js

2、导入自己的静态资源
springboot有默认的几个静态资源存放路径
项目下的:JAVA、RESOURCES都是classpath
classpath:/META-INF/resources/
classpath:/resources/
classpath:/static/
classpath:/public/
/ 项目根路径
springboot为以上所有路径都默认映射了起始面文件:index.html,即如果这些目录中有index.html时,访问这个目录时,页面会显示index.html的内容。
有相同资源时,Static目录的优先级比public的高
我在static目录下建了CSS目录,然后建了default.css,访问方式则如下:
http://localhost/css/default.css

3、默认的静态文件夹可以在项目属性文件中进行配置
spring.resources.static-location=classpath:/backman/,classpath:/hello/

猜你喜欢

转载自blog.csdn.net/weixin_40404189/article/details/88713694