springboot通过url访问项目外的其他目录下的图片

1.首先在application.properties文件中增加配置:

#资源绝对路径为file:D://sws/module-base/module-base/upload,图片存放的真实路径
#意思是springboot开放此资源路径供外部读取
spring.resources.static-locations=file:D://sws/module-base/module-base/upload
        
#资源映射路径为/image/**,使用url访问的请求路径
spring.mvc.static-path-pattern=/image/**

2.如果项目使用了权限认证,则需要将/image/** 添加在免认证的配置中,才能直接访问。 

如此便可以访问图片了:https://localhost:8050/image/731f594961834b4baed6057c68dd6cd1.jpg

猜你喜欢

转载自blog.csdn.net/weixin_38959210/article/details/107619844