SpringBoot项目的静态资源的访问及存放

版权声明:如需转载,请附上原文链接即可 https://blog.csdn.net/doujinlong1/article/details/82980128

在springBoot项目中,如果是只做后端的微服务,比较简单,直接写后端代码即可,但是部分情况下会需要页面的展示,所以在这个时候就需要进行一些配置来满足页面的展示

下面是application.yml文件中对静态资源访问的配置

spring:
  resources:
	#这个节点配置是设置静态文件存放的路径
	static-locations: file:///d:/(这个是放在本地硬盘上的,比如为D盘)
	static-locations: classpath:/static(这个是放在resources路径/类路径 下的static文件夹)
  mvc:
	#这个节点的配置是设置静态文件的访问的路径(http请求的)  
    static-path-pattern: //**

比如在我是这样设置的

spring:
  resources:
	#这个节点配置是设置静态文件存放的路径
	static-locations: classpath:/static(这个是放在resources路径/类路径 下的static文件夹)
  mvc:
	#这个节点的配置是设置静态文件的访问的路径(http请求的)  
    static-path-pattern: //**

那我在static文件夹放一个index.html文件,然后使用localhost:8080/index.html即可访问了。

猜你喜欢

转载自blog.csdn.net/doujinlong1/article/details/82980128
今日推荐