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

  • 相关阅读:
    一则Entity Framework 学习中的问题
    用于主题检测的临时日志(861e835361d543a9b1b4e055dac9cf39 3bfe001a32de4114a6b44005b770f6d7)
    同一数据库如果处理多个完全不同的业务?
    swif debounce实现
    SQL Server 2008 下载地址(微软官方网站)
    fastreport 3的安装步骤
    修改windows server 2008 时间和日期格式 IIS配置后显示错误
    SQL server2000数据库备份和还原语句
    安装oracle,创建并启动oracle实例(创建克隆数据库,进度条在45%)就进行不下去了
    使用poi读写excel文件
  • 原文地址:https://www.cnblogs.com/gagaAurora/p/14024090.html
Copyright © 2011-2022 走看看