Springboot项目中静态资源的处理
背景
在实际项目开发中,经常会遇到一些模板类的文件获取问题,这类文件配置好的不需要修改,只需要提供下载的地址,那么就会想到把这些模板放到静态资源中,这里只做后台静态资源的配置方式
springboot静态资源的集成
强大的springboot起始已经集成了静态资源区域,他的默认静态资源配置如下
classpath:/static
classpath:/public
classpath:/resources
classpath:/META-INF/resources
只要在项目中把你需要的静态资源放在这些路径下,就可以直接访问
测试
http://localhost:8080/index.html
结果
自定义静态资源路径
在springboot中有两个参数可以配置静态资源访问路径
# 静态文件请求匹配方式
spring.mvc.static-path-pattern=/**
# 默认的静态寻址资源目录 多个使用逗号分隔
spring.resources.static-locations = classpath:/META-INF/resources/,classpath:/resources/,classpath:/static/,classpath:/public/
如果需要新定义地址可以在后面添加
测试
http://localhost:8080/static/demo.html
结果
参考文档:https://blog.csdn.net/zhoujiyu123/article/details/80255445