已解决
springBoot--web--静态资源规则
来自网友在路上 156856提问 提问时间:2023-10-23 17:07:50阅读次数: 56
最佳答案 问答题库568位专家为你答疑解惑
规则一:
访问:/webjars/** 路径就去 classpath:/META-INF/resources/webjars/下载资源
a.maven导入依赖
规则二:
访问:/** 路径就去 静态资源默认的四个位置找资源
a. classpath:/META-INF/resources/
b.classpath:/resources/
c.classpath:/statice/
d.classpath:/public/
规则三:静态资源默认都有缓存规则的设置
a、所有缓存设置,直接通过配置文件: spring.web
b、cachePeriod:缓存周期,多久不用找服务器要新的,默认没有,以s为单位
c、cacheControl:Http缓存控制:
HTTP 缓存 - HTTP | MDN
d、userLastModified: 是否使用最后一次修改,配合HTTP Cache规则
如果浏览器访问静态资源index.js,如果服务这个资源没有发生变化,下次访问的时候就可以直接让浏览器用自己缓存中的东西,而不用给服务器发送请求
registration.setCachePeriod(this.getSeconds(this.resourceProperties.getCache().getPeriod())); registration.setCacheControl(this.resourceProperties.getCache().getCachecontrol().toHttpCacheControl()); registration.setUseLastModified(this.resourceProperties.getCache().isUseLastModified());
静态资源配置
在配置文件中配置静态资源路径
#自定义静态资源文件夹位置
spring.web.resources.static-locations=classpath:/a/,classpath:/b/,classPath:/static/#自定义webjars路径
spring.mvc.webjars-path-pattern=/wj/**
#静态资源访问路径前缀
spring.mvc.static-path-pattern=/static/**
查看全文
99%的人还看了
相似问题
猜你感兴趣
版权申明
本文"springBoot--web--静态资源规则":http://eshow365.cn/6-22609-0.html 内容来自互联网,请自行判断内容的正确性。如有侵权请联系我们,立即删除!