• springBoot--web--静态资源规则


    规则一:

    访问:/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());

    静态资源配置

    在配置文件中配置静态资源路径

    1. #自定义静态资源文件夹位置
    2. spring.web.resources.static-locations=classpath:/a/,classpath:/b/,classPath:/static/
    3. #自定义webjars路径
    4. spring.mvc.webjars-path-pattern=/wj/**
    5. #静态资源访问路径前缀
    6. spring.mvc.static-path-pattern=/static/**

  • 相关阅读:
    docker-compose安装rocketmq 5
    算法进阶-2sat-cf-875C
    TensorFlow 的基本概念和使用场景
    电脑提示“系统找不到指定的文件”怎么办?
    Spring MVC
    Git的使用
    记录ajax的jsonp类型请求
    KMP算法,next表的创建。
    MailStore Server标准的电子邮件归档
    Linux项目自动化构建工具-make/Makefile
  • 原文地址:https://blog.csdn.net/m0_50207524/article/details/133923090