SpringBoot如何访问静态资源(bo,springboot,静态资源,开发技术)

时间:2024-05-03 20:38:22 作者 : 石家庄SEO 分类 : 开发技术
  • TAG :

springboot访问静态资源,默认有两个默认目录,

一个是 classpath/static 目录 (src/mian/resource)

一个是 ServletContext 根目录下( src/main/webapp)

这在里可能有小伙伴对 classpath 不怎么了解,这里简要的介绍下,classpath即WEB-INF下面的classes目录 ,在springboot项目中可能就是,src/main/resource 目录。

1,classpath 目录下-访问默认文件夹名为 static

目录截图:

SpringBoot如何访问静态资源

访问截图:

SpringBoot如何访问静态资源

这里有人就想说,我可不可以修改一下访问路径呢,答案是肯定的,肯定可以。

在 properties文件里面设置 spring.resources.static-locations 就ok了

spring.resources.static-locations 的默认值是:classpath:/META-INF/resources/,classpath:/resources/,classpath:/static/,classpath:/public/

图示修改:我将默认路径改成了 src/main/resource/static/images/,在里面我写了一个 index.html 里面写的 html img

SpringBoot如何访问静态资源

访问的时候就找的是我设置的路径了。

2.ServletContext 根目录下( src/main/webapp) - webapp 就是默认访问文件夹

这个可能很多人就不陌生了,一般来说 src/main/java 里面放Java代码,resource 里面放 配置文件。xml, webapp里面放页面,js之类的。

ServletContent 根目录就是 src/main/webapp

一般创建的maven项目里面都没有 webapp 文件夹,在这里我们自己在 src/main 目录下创建一个 webapp

项目目录,以及访问截图:

SpringBoot如何访问静态资源

 </div> <div class="zixun-tj-product adv-bottom"></div> </div> </div> <div class="prve-next-news">
本文:SpringBoot如何访问静态资源的详细内容,希望对您有所帮助,信息来源于网络。
上一篇:教你几个实用的vs调试技巧下一篇:

24 人围观 / 0 条评论 ↓快速评论↓

(必须)

(必须,保密)

阿狸1 阿狸2 阿狸3 阿狸4 阿狸5 阿狸6 阿狸7 阿狸8 阿狸9 阿狸10 阿狸11 阿狸12 阿狸13 阿狸14 阿狸15 阿狸16 阿狸17 阿狸18