SpringBoot2.X文件路径映射

实现的接口WebMvcConfigurer

public interface WebMvcConfigurer {
    default void configurePathMatch(PathMatchConfigurer configurer) {}

    default void configureContentNegotiation(ContentNegotiationConfigurer configurer) {}

    default void configureAsyncSupport(AsyncSupportConfigurer configurer) {}

    default void configureDefaultServletHandling(DefaultServletHandlerConfigurer configurer) {}

    default void addFormatters(FormatterRegistry registry) {}

    default void addInterceptors(InterceptorRegistry registry) {}

    default void addResourceHandlers(ResourceHandlerRegistry registry) {}

    default void addCorsMappings(CorsRegistry registry) {}

    default void addViewControllers(ViewControllerRegistry registry) {}

    default void configureViewResolvers(ViewResolverRegistry registry) {}

    default void addArgumentResolvers(List<HandlerMethodArgumentResolver> resolvers) {}

    default void addReturnValueHandlers(List<HandlerMethodReturnValueHandler> handlers) {}

    default void configureMessageConverters(List<HttpMessageConverter<?>> converters) {}

    default void extendMessageConverters(List<HttpMessageConverter<?>> converters) {}

    default void configureHandlerExceptionResolvers(List<HandlerExceptionResolver> resolvers) {}

    default void extendHandlerExceptionResolvers(List<HandlerExceptionResolver> resolvers) {}

    @Nullable
    default Validator getValidator() {
        return null;
    }

    @Nullable
    default MessageCodesResolver getMessageCodesResolver() {
        return null;
    }
}

既然WebMvcConfigurer默认有空实现,那么直接实现WebMvcConfigurer接口即可:

@Configuration
public class FilePathConfig implements WebMvcConfigurer {
        // 文件路径基于 MacOS 环境
    private String images = "/Users/****/Desktop/demo/file/";
        private String mode = "/Users/****/Desktop/demo/file/mode/";

    @Override
    public void addResourceHandlers(ResourceHandlerRegistry registry) {
        registry.addResourceHandler("/images/**").addResourceLocations("file:"+images);
        registry.addResourceHandler("/modes/**").addResourceLocations("file:"+mode);
        WebMvcConfigurer.super.addResourceHandlers(registry);
    }

暂无评论

发送评论 编辑评论


				
|´・ω・)ノ
ヾ(≧∇≦*)ゝ
(☆ω☆)
(╯‵□′)╯︵┴─┴
 ̄﹃ ̄
(/ω\)
∠( ᐛ 」∠)_
(๑•̀ㅁ•́ฅ)
→_→
୧(๑•̀⌄•́๑)૭
٩(ˊᗜˋ*)و
(ノ°ο°)ノ
(´இ皿இ`)
⌇●﹏●⌇
(ฅ´ω`ฅ)
(╯°A°)╯︵○○○
φ( ̄∇ ̄o)
ヾ(´・ ・`。)ノ"
( ง ᵒ̌皿ᵒ̌)ง⁼³₌₃
(ó﹏ò。)
Σ(っ °Д °;)っ
( ,,´・ω・)ノ"(´っω・`。)
╮(╯▽╰)╭
o(*////▽////*)q
>﹏<
( ๑´•ω•) "(ㆆᴗㆆ)
😂
😀
😅
😊
🙂
🙃
😌
😍
😘
😜
😝
😏
😒
🙄
😳
😡
😔
😫
😱
😭
💩
👻
🙌
🖕
👍
👫
👬
👭
🌚
🌝
🙈
💊
😶
🙏
🍦
🍉
😣
Source: github.com/k4yt3x/flowerhd
颜文字
Emoji
小恐龙
花!
上一篇
下一篇