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

  • 相关阅读:
    为什么button在设置标题时要用一个方法,而不像lable一样直接用一个属性
    桥接模式(透传模式)和直驱模式
    vb.net版机房收费系统——教你七层架构(三)—外观模式
    Android 4.4 KitKat NotificationManagerService使用具体解释与原理分析(二)__原理分析
    poj-2758 Checking the Text
    一种感悟,为什么努力了确还是死了一地
    一位程序员的6年总结(转)
    主键生成策略
    Linux下的crontab定时执行任务命令详解
    win7 64下安装mysql-python报错的解决办法
  • 原文地址:https://www.cnblogs.com/gagaAurora/p/14024090.html
Copyright © 2011-2022 走看看