建立配置文件,使用config注解,代码如下:
1 2 3 4 5 6 7 8 9 10 11 12
| @Configuration public class ImgConfig implements WebMvcConfigurer { @Value("${savePath.profilePhoto}") private String profilePhotoPath; @Value("${savePath.profilePhotoMapper}") private String profilePhotoMapperPath; @Override public void addResourceHandlers(ResourceHandlerRegistry registry){ registry.addResourceHandler(profilePhotoMapperPath+"**").addResourceLocations("file:"+profilePhotoPath); } }
|
注意:前面的profilePhotoMapperPath是映射的路径,后面的profilePhotoPath真实路径,这个地方是容易写错的地方
1 2 3
| savePath: profilePhoto: "F:/gis2.0updata/gisimg/" #图标存储路径 profilePhotoMapper: "/img/" #图标的映射路径
|