Spring项目通过URL访问静态图片和本地文件夹下的图片
1.如果文件不多可以把图片资源放在SpringBoot项目的静态文件夹中
在配置文件中加上:spring.mvc.static-path-pattern= /** 或者在yml配置文件中加上:
spring: mvc: static-path-pattern: /**
配置好后重新启动SpringBoot 接下来就可以在浏览器中访问了:http://192.168.200.106:8081/girl/images/1.jpg
2.如果有多张图片 图片在本地硬盘:
在配置文件中配置:
spring.resources.static-locations= file:/Users/jason/Downloads/SpringBootProject/Pic/
或者在yml 中配置:
spring: resources: static-locations: file:/Users/jason/Downloads/SpringBootProject/Pic/
配置好以后 同样在浏览器中测试:http://localhost:8081/girl/Test.jpeg 这里URL 中就不需要文件夹路径了
如果是在安卓端用图片加载框架加载图片和加载其他图片是一样的:
Glide.with(this) .load("http://192.168.200.106:8081/girl/Test.jpeg") .placeholder(R.drawable.icon_avatar) .fitCenter() .dontAnimate() .into((mCircleImageView));
大功告成
作者Github:https://github.com/HuaDanJson