地元の絵にアクセスするためのURLによってspringboot

1. JARパッケージの紹介

<依存> 
    <groupIdを> org.springframework.boot </ groupIdを> 
    <たartifactId>春・ブート・スターター・ウェブ</たartifactId> 
</依存関係>

コンフィギュレーション・クラスを作成します。2.

パッケージcom.common.config。

輸入org.springframework.beans.factory.annotation.Value;
輸入org.springframework.context.annotation.Configuration。
輸入org.springframework.web.servlet.config.annotation.ResourceHandlerRegistry;
輸入org.springframework.web.servlet.config.annotation.WebMvcConfigurer; 

/ ** 
 * @BelongsProject:デモ
 * @Author:DanBrown 
 * @CreateTime:2020年3月28日午後2時33分
 * @description:TODO 
 * / 
@Configuration 
パブリック クラスのWebConfig 実装WebMvcConfigurer { 
    @value(「$ {} upload.path " プライベートUploadPath文字列; 

    @Override 
    公共 無効addResourceHandlers(ResourceHandlerRegistryレジストリ){
         //   ファイルの背後にあるフロントエンドのアクセス・パスのために/ホーム/ファイル/ ** URL:xxxxのローカルディスクのマッピング 
        registry.addResourceHandler( "/ホーム/ファイル/ **")。 addResourceLocations( "ファイル:C:" + uploadPath); 
    } 

}

3.アクセス

http:// localhost:8080 /ホーム/ファイル/ 820123.png

おすすめ

転載: www.cnblogs.com/DanBrown/p/12588768.html