springboot(10)- 整合web開發(2)- 靜態資源訪問

1 靜態資源訪問

在這裏插入圖片描述
在這裏插入圖片描述

2 兩種方式自定義靜態資源訪問位置

2.1 方式1

在這裏插入圖片描述
在這裏插入圖片描述

2.2 方式2

package com.tzb.config;

import org.springframework.context.annotation.Configuration;
import org.springframework.web.servlet.config.annotation.ResourceHandlerRegistry;
import org.springframework.web.servlet.config.annotation.WebMvcConfigurer;

@Configuration
public class WebMvcConfig implements WebMvcConfigurer {

    @Override
    public void addResourceHandlers(ResourceHandlerRegistry registry) {
        registry.addResourceHandler("/**")
                .addResourceLocations("classpath:/mylocation/");
    }
}

發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章