springboot内置tomcat配置本地文件夹的映射路径

例如要访问的本地路径是D盘下的PersonalHomePage目录的某个图片

 1 import org.springframework.context.annotation.Configuration;
 2 import org.springframework.web.servlet.config.annotation.ResourceHandlerRegistry;
 3 import org.springframework.web.servlet.config.annotation.WebMvcConfigurer;
 4 
 5 /**
 6  * 资源映射路径
 7  */
 8 @Configuration
 9 public class MyWebAppConfigurer implements WebMvcConfigurer {
10     @Override
11     public void addResourceHandlers(ResourceHandlerRegistry registry) {
12         registry.addResourceHandler("/PersonalHomePage/**").addResourceLocations("file:D:/PersonalHomePage/");
13     }
14 }

http://192.168.1.120:8083/PersonalHomePage/t6.jpg

 

posted @ 2022-09-19 10:52  莴苣&  阅读(809)  评论(0编辑  收藏  举报