zoukankan      html  css  js  c++  java
  • SpringBoot对静态资源的映射规则

    public void addResourceHandlers(ResourceHandlerRegistry registry) {
                if (!this.resourceProperties.isAddMappings()) {
                    logger.debug("Default resource handling disabled");
                } else {
                    Duration cachePeriod = this.resourceProperties.getCache().getPeriod();
                    CacheControl cacheControl = this.resourceProperties.getCache().getCachecontrol().toHttpCacheControl();
                    if (!registry.hasMappingForPattern("/webjars/**")) {
                        this.customizeResourceHandlerRegistration(registry.addResourceHandler(new String[]{"/webjars/**"}).addResourceLocations(new String[]{"classpath:/META-INF/resources/webjars/"}).setCachePeriod(this.getSeconds(cachePeriod)).setCacheControl(cacheControl).setUseLastModified(this.resourceProperties.getCache().isUseLastModified()));
                    }
    
                    String staticPathPattern = this.mvcProperties.getStaticPathPattern();
                    if (!registry.hasMappingForPattern(staticPathPattern)) {
                        this.customizeResourceHandlerRegistration(registry.addResourceHandler(new String[]{staticPathPattern}).addResourceLocations(WebMvcAutoConfiguration.getResourceLocations(this.resourceProperties.getStaticLocations())).setCachePeriod(this.getSeconds(cachePeriod)).setCacheControl(cacheControl).setUseLastModified(this.resourceProperties.getCache().isUseLastModified()));
                    }
    
                }
            }
    
    •   所有
      /webjars/**都去
      classpath:/META-INF/resources/webjars/找资源;        webjars:以jar的方式导入静态资源;https://www.webjars.org/
      
      

       localhost:8081/webjars/jquery/3.3.1/jquery.js访问

         <!--    引入jquery的web模块-->在访问的时候只需要写webjars下的资源的名称
          <dependency>
            <groupId>org.webjars</groupId>
            <artifactId>jquery</artifactId>
            <version>3.3.1</version>
          </dependency>
      

       2./**   访问当前项目的任何资源,(静态资源的文件夹)

      
      
    • “classPath:/META-INF/resources/”
      "classPath:/resources/"
      "classPath:/static/"
      "classPath:/public"
      "/" 当前项目根路径
      

        localhost:8081/abc ===去静态资源文件夹下找abc

    //配置欢迎页的映射   
    @Bean public WelcomePageHandlerMapping welcomePageHandlerMapping(ApplicationContext applicationContext, FormattingConversionService mvcConversionService, ResourceUrlProvider mvcResourceUrlProvider) { WelcomePageHandlerMapping welcomePageHandlerMapping = new WelcomePageHandlerMapping(new TemplateAvailabilityProviders(applicationContext), applicationContext, this.getWelcomePage(), this.mvcProperties.getStaticPathPattern()); welcomePageHandlerMapping.setInterceptors(this.getInterceptors(mvcConversionService, mvcResourceUrlProvider)); welcomePageHandlerMapping.setCorsConfigurations(this.getCorsConfigurations()); return welcomePageHandlerMapping; }

      3.欢迎页,静态资源文件夹下的所以index.html页面; 被/**映射

    localhost:8081/ 找index

  • 相关阅读:
    WebStorm 2018版本破解方法
    C# WMI通过网络连接名称获取IP掩码网关
    c# 调用RDP和SSH实现远程登陆
    LabVIEW中开放隐藏属性的inikey
    LabVIEW类方法浏览器-Class Method Browser
    hive split 注意事项
    机器学习三大框架对比
    Windows环境下搭建Nginx和多版本PHP共存
    javascript : location 对象
    ora-00031:session marked for kill处理oracle中杀不掉的锁
  • 原文地址:https://www.cnblogs.com/gagaAurora/p/14024090.html
Copyright © 2011-2022 走看看