最新国产好看的视频,伊人天堂AV在线,国产Aaaaaa视频,蜜臀视频在线观看一区,人妻av色图,密臀久久久精品影片,青青视频免费观看毛片,久草在线观看视,国产三级精品色情在线

SpringBoot如何通過webjars管理靜態(tài)資源文件夾

 更新時間:2020年10月30日 11:18:42   作者:圣金巫靈  
這篇文章主要介紹了SpringBoot如何通過webjars管理靜態(tài)資源文件夾,文中通過示例代碼介紹的非常詳細,對大家的學(xué)習(xí)或者工作具有一定的參考學(xué)習(xí)價值,需要的朋友可以參考下

WebMvcAutoConfiguration

添加資源映射:

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));
        }

        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));
        }

      }
    }

所有"/webjars/**"路徑 , 都去類路徑下 classpath: /META-INF/resources/webjars/ 找資源,
所以就是

http://localhost:8080/webjars/jquery/3.5.1/jquery.js

能訪問

/META-INF/resources/webjars/jquery/3.5.1/jquery.js 路徑的文件

1) webjars: 以jar包的方式引入靜態(tài)資源

什么是webjar?

搜索webjar, 可以將jquery用pom引入:

引入, 正好對應(yīng)這個映射:

結(jié)果是的:

2) springboot對靜態(tài)資源的映射規(guī)則:

看代碼:

還是

WebMvcAutoConfiguration的這個方法

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));
    }

    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));
    }
  }
}

進去:

WebMvcProperties

private String staticPathPattern;
  private final WebMvcProperties.Async async;
  private final WebMvcProperties.Servlet servlet;
  private final WebMvcProperties.View view;
  private final WebMvcProperties.Contentnegotiation contentnegotiation;
  private final WebMvcProperties.Pathmatch pathmatch;

  public WebMvcProperties() {
    this.localeResolver = WebMvcProperties.LocaleResolver.ACCEPT_HEADER;
    this.format = new WebMvcProperties.Format();
    this.dispatchTraceRequest = false;
    this.dispatchOptionsRequest = true;
    this.ignoreDefaultModelOnRedirect = true;
    this.publishRequestHandledEvents = true;
    this.throwExceptionIfNoHandlerFound = false;
    this.logResolvedException = false;
    this.staticPathPattern = "/**";
    this.async = new WebMvcProperties.Async();
    this.servlet = new WebMvcProperties.Servlet();
    this.view = new WebMvcProperties.View();
    this.contentnegotiation = new WebMvcProperties.Contentnegotiation();
    this.pathmatch = new WebMvcProperties.Pathmatch();
  }

addResourceLocations(WebMvcAutoConfiguration.getResourceLocations(this.resourceProperties.getStaticLocations())) 這里添加了資源的位置

public class ResourceProperties {
  private static final String[] CLASSPATH_RESOURCE_LOCATIONS = new String[]{"classpath:/META-INF/resources/", "classpath:/resources/", "classpath:/static/", "classpath:/public/"};
  private String[] staticLocations;
  private boolean addMappings;
  private final ResourceProperties.Chain chain;
  private final ResourceProperties.Cache cache;

  public ResourceProperties() {
    this.staticLocations = CLASSPATH_RESOURCE_LOCATIONS;
    this.addMappings = true;
    this.chain = new ResourceProperties.Chain();
    this.cache = new ResourceProperties.Cache();
  }

"/**"訪問當前項目的任何資源, (靜態(tài)資源的文件夾) ,如果沒人處理,會默認去以下幾個文件路徑下找[/code]

復(fù)制代碼 代碼如下:
// 靜態(tài)資源文件夾, 這幾個都可以存放靜態(tài)資源:

classpath:/META-INF/resources/classpath:/resources/"classpath:/static/"classpath:/public/

例如 localhost:8080/a/b.js , 可以到 /META-INF/resources/a/b.js 找

或者:

/resources/a/b.js找:

或者類路徑下/static/a/b.js找:

或者/public/a/b.js下找

3)歡迎頁面: 靜態(tài)資源文件夾下的所有index.html頁面: 被 /**映射

http://localhost:8080/ 會到以上靜態(tài)資源文件夾中找index.html頁面

源碼有變化,我沒明白回頭再看

結(jié)果:

路徑:

以上就是本文的全部內(nèi)容,希望對大家的學(xué)習(xí)有所幫助,也希望大家多多支持腳本之家。

相關(guān)文章

  • SpringBoot+Mybatis實現(xiàn)登錄注冊的示例代碼

    SpringBoot+Mybatis實現(xiàn)登錄注冊的示例代碼

    這篇文章主要介紹了SpringBoot+Mybatis實現(xiàn)登錄注冊的示例代碼,文中通過示例代碼介紹的非常詳細,對大家的學(xué)習(xí)或者工作具有一定的參考學(xué)習(xí)價值,需要的朋友們下面隨著小編來一起學(xué)習(xí)學(xué)習(xí)吧
    2021-03-03
  • Spring中容器的創(chuàng)建流程詳細解讀

    Spring中容器的創(chuàng)建流程詳細解讀

    這篇文章主要介紹了Spring中容器的創(chuàng)建流程詳細解讀,Spring?框架其本質(zhì)是作為一個容器,提供給應(yīng)用程序需要的對象,了解容器的誕生過程,有助于我們理解?Spring?框架,也便于我們“插手”這個過程,需要的朋友可以參考下
    2023-10-10
  • SpringBoot啟動時運行特定代碼的多種方式小結(jié)

    SpringBoot啟動時運行特定代碼的多種方式小結(jié)

    SpringBoot提供了多種方式在應(yīng)用程序啟動時運行特定的代碼,包括CommandLineRunner、ApplicationRunner、@PostConstruct、InitializingBean、事件機制和自定義注解等,下面就來具體介紹一下
    2025-01-01
  • 使用mybatis插件PageHelper實現(xiàn)分頁效果

    使用mybatis插件PageHelper實現(xiàn)分頁效果

    這篇文章主要為大家詳細介紹了使用mybatis插件PageHelper實現(xiàn)分頁效果,文中示例代碼介紹的非常詳細,具有一定的參考價值,感興趣的小伙伴們可以參考一下
    2019-01-01
  • Java項目如何打包成Jar的實現(xiàn)步驟

    Java項目如何打包成Jar的實現(xiàn)步驟

    一般情況下我們都是使用Java項目直接部署發(fā)布,有時需要我們將寫好的項目打成jar包,方便后期調(diào)用,本文主要介紹了Java項目如何打包成Jar,感興趣的可以了解一下
    2023-11-11
  • MyBatis如何處理MySQL字段類型date與datetime

    MyBatis如何處理MySQL字段類型date與datetime

    這篇文章主要介紹了MyBatis如何處理MySQL字段類型date與datetime問題,具有很好的參考價值,希望對大家有所幫助,如有錯誤或未考慮完全的地方,望不吝賜教
    2024-01-01
  • java實現(xiàn)哈夫曼文件解壓縮

    java實現(xiàn)哈夫曼文件解壓縮

    這篇文章主要為大家詳細介紹了java實現(xiàn)哈夫曼文件解壓縮,文中示例代碼介紹的非常詳細,具有一定的參考價值,感興趣的小伙伴們可以參考一下
    2021-06-06
  • Java常用API類之Math System tostring用法詳解

    Java常用API類之Math System tostring用法詳解

    System類代表系統(tǒng),系統(tǒng)級的很多屬性和控制方法都放置在該類的內(nèi)部。該類位于java.lang包,Java 的 Math 包含了用于執(zhí)行基本數(shù)學(xué)運算的屬性和方法,如初等指數(shù)、對數(shù)、平方根和三角函數(shù),toString() 方法用于返回以一個字符串表示的 Number 對象值
    2021-10-10
  • java變量的聲明與賦值分離規(guī)范示例

    java變量的聲明與賦值分離規(guī)范示例

    這篇文章主要為大家介紹了java變量的聲明與賦值分離規(guī)范示例,有需要的朋友可以借鑒參考下,希望能夠有所幫助,祝大家多多進步,早日升職加薪
    2023-09-09
  • Java如何讀寫Properties配置文件(Properties類)

    Java如何讀寫Properties配置文件(Properties類)

    這篇文章主要介紹了Java如何讀寫Properties配置文件(Properties類),具有很好的參考價值,希望對大家有所幫助。如有錯誤或未考慮完全的地方,望不吝賜教
    2023-05-05

最新評論

鄂托克前旗| 宿松县| 盐城市| 仲巴县| 宁德市| 会泽县| 黄大仙区| 井陉县| 万全县| 台南市| 浦北县| 宜春市| 肇州县| 丹寨县| 南丹县| 当涂县| 桑日县| 海口市| 迁安市| 潮安县| 循化| 五莲县| 泰宁县| 子长县| 东海县| 屯昌县| 安康市| 高安市| 汝城县| 福贡县| 太谷县| 瑞金市| 略阳县| 水富县| 乡宁县| 盘山县| 沾化县| 宁南县| 正宁县| 台中市| 横山县|