SpringBoot 加载远程图片

 

logo:

 

 

 

第一步:

确保是web项目

映射请求到图片路径下

相对路径:registry.addResourceHandler("/static/**").addResourceLocations("classpath:/templates/static/");

绝对路径:registry.addResourceHandler("/image/**").addResourceLocations("file:" + SystemAPI.filePath);

注意:SystemAPI.filePath为要访问的文件夹路径

整体代码如图

实现以上两步便可以通过URL(http://192.168.2.105:5005/image/430425196910236722.jpg)请求到SystemAPI.filPath路径下的图片 

 

posted @ 2020-12-08 16:07  java小奔奔  阅读(855)  评论(0)    收藏  举报

公众号【嗨呀搜索】