欧美bbbwbbbw肥妇,免费乱码人妻系列日韩,一级黄片

SpringBoot對靜態(tài)資源的映射規(guī)則詳解解讀

 更新時(shí)間:2023年10月27日 09:09:19   作者:夜聆離殤  
這篇文章主要介紹了SpringBoot對靜態(tài)資源的映射規(guī)則詳解解讀,在Spring Boot中,映射規(guī)則是用來定義URL與控制器方法之間的映射關(guān)系的,通過映射規(guī)則,可以將特定的URL請求映射到相應(yīng)的控制器方法上,從而實(shí)現(xiàn)請求的處理和響應(yīng)的返回,需要的朋友可以參考下

Spring Boot對靜態(tài)資源的映射規(guī)則

1.所有/webjars/**,都去classpath:/META-INF/resources/webjars/找資源

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

<!‐‐引入jquery‐webjar,在訪問的時(shí)候只需要寫webjars下面資源的名稱即可‐‐>
<dependency>
    <groupId>org.webjars</groupId>
    <artifactId>jquery</artifactId>
    <version>3.4.1</version>
</dependency>

  • 訪問路徑://127.0.0.1:8089/webjars/jquery/3.4.1/jquery.js

2. "/**" 訪問當(dāng)前項(xiàng)目的任何資源,都去(靜態(tài)資源的文件夾)找映射

"classpath:/META‐INF/resources/",
"classpath:/resources/",
"classpath:/static/",
"classpath:/public/"

"/":當(dāng)前項(xiàng)目的根路徑

localhost:8080/abc === 去靜態(tài)資源文件夾里面找abc

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

localhost:8089/:找首頁(index.html)

4. 所有的 **/favicon.ico都是在靜態(tài)資源文件下找的。

    @Override
        public void addResourceHandlers(ResourceHandlerRegistry registry) {
            if (!this.resourceProperties.isAddMappings()) {
                logger.debug("Default resource handling disabled");
                return;
            }
            Duration cachePeriod = this.resourceProperties.getCache().getPeriod();
            CacheControl cacheControl = this.resourceProperties.getCache().getCachecontrol().toHttpCacheControl();
            if (!registry.hasMappingForPattern("/webjars/**")) {
                customizeResourceHandlerRegistration(registry.addResourceHandler("/webjars/**")
                        .addResourceLocations("classpath:/META-INF/resources/webjars/")
                        .setCachePeriod(getSeconds(cachePeriod)).setCacheControl(cacheControl));
            }
            String staticPathPattern = this.mvcProperties.getStaticPathPattern();
       //靜態(tài)資源文件夾映射
            if (!registry.hasMappingForPattern(staticPathPattern)) {
                customizeResourceHandlerRegistration(registry.addResourceHandler(staticPathPattern)
                        .addResourceLocations(getResourceLocations(this.resourceProperties.getStaticLocations()))
                        .setCachePeriod(getSeconds(cachePeriod)).setCacheControl(cacheControl));
            }
        }

配置歡迎頁映射

    @Bean
        public WelcomePageHandlerMapping welcomePageHandlerMapping(ApplicationContext applicationContext) {
            WelcomePageHandlerMapping welcomePageHandlerMapping = new WelcomePageHandlerMapping(
                    new TemplateAvailabilityProviders(applicationContext), applicationContext, getWelcomePage(),
                    this.mvcProperties.getStaticPathPattern());
            welcomePageHandlerMapping.setInterceptors(getInterceptors());
            return welcomePageHandlerMapping;
        }
@Configuration
        @ConditionalOnProperty(value = "spring.mvc.favicon.enabled", matchIfMissing = true)
        public static class FaviconConfiguration implements ResourceLoaderAware {
            private final ResourceProperties resourceProperties;
            private ResourceLoader resourceLoader;
            public FaviconConfiguration(ResourceProperties resourceProperties) {
                this.resourceProperties = resourceProperties;
            }
            @Override
            public void setResourceLoader(ResourceLoader resourceLoader) {
                this.resourceLoader = resourceLoader;
            }
       //  映射**/favicon.ico
            @Bean
            public SimpleUrlHandlerMapping faviconHandlerMapping() {
                SimpleUrlHandlerMapping mapping = new SimpleUrlHandlerMapping();
                mapping.setOrder(Ordered.HIGHEST_PRECEDENCE + 1);
                mapping.setUrlMap(Collections.singletonMap("**/favicon.ico", faviconRequestHandler()));
                return mapping;
            }
            @Bean
            public ResourceHttpRequestHandler faviconRequestHandler() {
                ResourceHttpRequestHandler requestHandler = new ResourceHttpRequestHandler();
                requestHandler.setLocations(resolveFaviconLocations());
                return requestHandler;
            }
            private List<Resource> resolveFaviconLocations() {
                String[] staticLocations = getResourceLocations(this.resourceProperties.getStaticLocations());
                List<Resource> locations = new ArrayList<>(staticLocations.length + 1);
                Arrays.stream(staticLocations).map(this.resourceLoader::getResource).forEach(locations::add);
                locations.add(new ClassPathResource("/"));
                return Collections.unmodifiableList(locations);
            }
        }
    }

到此這篇關(guān)于SpringBoot對靜態(tài)資源的映射規(guī)則詳解解讀的文章就介紹到這了,更多相關(guān)SpringBoot靜態(tài)資源的映射規(guī)則內(nèi)容請搜索腳本之家以前的文章或繼續(xù)瀏覽下面的相關(guān)文章希望大家以后多多支持腳本之家!

相關(guān)文章

  • Java 內(nèi)省(Introspector)深入理解

    Java 內(nèi)省(Introspector)深入理解

    這篇文章主要介紹了Java 內(nèi)省(Introspector)深入理解的相關(guān)資料,需要的朋友可以參考下
    2017-03-03
  • Struts2學(xué)習(xí)筆記(1)-入門教程

    Struts2學(xué)習(xí)筆記(1)-入門教程

    本文是一個(gè)Struts2的簡單入門教程,比較簡單,希望能給大家做一個(gè)參考。
    2016-06-06
  • Java?JDBC使用入門講解

    Java?JDBC使用入門講解

    JDBC是指Java數(shù)據(jù)庫連接,是一種標(biāo)準(zhǔn)Java應(yīng)用編程接口(?JAVA?API),用來連接?Java?編程語言和廣泛的數(shù)據(jù)庫。從根本上來說,JDBC?是一種規(guī)范,它提供了一套完整的接口,允許便攜式訪問到底層數(shù)據(jù)庫,本篇文章我們來了解MySQL連接JDBC的流程方法
    2022-12-12
  • Spring Task定時(shí)任務(wù)的配置和使用詳解

    Spring Task定時(shí)任務(wù)的配置和使用詳解

    本篇文章主要介紹了Spring Task定時(shí)任務(wù)的配置和使用詳解,實(shí)例分析了Spring Task定時(shí)任務(wù)的配置和使用的技巧,非常具有實(shí)用價(jià)值,需要的朋友可以參考下
    2017-04-04
  • 關(guān)于Java中方法引用的示例

    關(guān)于Java中方法引用的示例

    方法引用可以認(rèn)為是Lambda表達(dá)式的一種特殊形式,Lambda表達(dá)式可以讓開發(fā)者自定義抽象方法的實(shí)現(xiàn)代碼,方法引用則可以讓開發(fā)者直接引用已存在的實(shí)現(xiàn)方法,作為Lambda表達(dá)式的Lambda體(參數(shù)列表得一致),需要的朋友可以參考下
    2023-05-05
  • 基于SpringBoot與Mybatis實(shí)現(xiàn)SpringMVC Web項(xiàng)目

    基于SpringBoot與Mybatis實(shí)現(xiàn)SpringMVC Web項(xiàng)目

    這篇文章主要介紹了基于SpringBoot與Mybatis實(shí)現(xiàn)SpringMVC Web項(xiàng)目的相關(guān)資料,需要的朋友可以參考下
    2017-04-04
  • Hibernate雙向一對一映射關(guān)系配置代碼實(shí)例

    Hibernate雙向一對一映射關(guān)系配置代碼實(shí)例

    這篇文章主要介紹了Hibernate雙向一對一映射關(guān)系配置代碼實(shí)例,文中通過示例代碼介紹的非常詳細(xì),對大家的學(xué)習(xí)或者工作具有一定的參考學(xué)習(xí)價(jià)值,需要的朋友可以參考下
    2020-10-10
  • Git設(shè)置和取消代理的方法

    Git設(shè)置和取消代理的方法

    今天小編就為大家分享一篇關(guān)于Git設(shè)置和取消代理的方法,小編覺得內(nèi)容挺不錯(cuò)的,現(xiàn)在分享給大家,具有很好的參考價(jià)值,需要的朋友一起跟隨小編來看看吧
    2018-12-12
  • 如何使用Spring Cloud Feign日志查看請求響應(yīng)

    如何使用Spring Cloud Feign日志查看請求響應(yīng)

    這篇文章主要介紹了如何使用Spring Cloud Feign日志查看請求響應(yīng),文中通過示例代碼介紹的非常詳細(xì),對大家的學(xué)習(xí)或者工作具有一定的參考學(xué)習(xí)價(jià)值,需要的朋友可以參考下
    2020-02-02
  • Java ArrayDeque實(shí)現(xiàn)Stack的功能

    Java ArrayDeque實(shí)現(xiàn)Stack的功能

    這篇文章主要介紹了Java ArrayDeque實(shí)現(xiàn)Stack功能的方法,具有一定的參考價(jià)值,感興趣的小伙伴們可以參考一下
    2016-03-03

最新評論