java配置图片访问映射
Administrator
2 阅读
博客
建立配置文件,使用config注解,代码如下:
@Configuration
public class ImgConfig implements WebMvcConfigurer {
//@Value可以将配置文件的内容自动注入到属性内
@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真实路径,这个地方是容易写错的地方
savePath:
profilePhoto: "F:/gis2.0updata/gisimg/" #图标存储路径
profilePhotoMapper: "/img/" #图标的映射路径
|