配置application.yml
file: path: windows: D:desktophomeidea_homezhzfpic linux: /Users/lhk/Desktop/zhzf/pic/
配置WebMvcConfig
windowsFilePath:windows系统本地静态资源的真实地址(对应application.yml中的windows)
linuxFilePath:linux系统本地静态资源的真实地址(对应application.yml中的linux)
通过registry.addResourceHandler("/img @Override public void addResourceHandlers(ResourceHandlerRegistry registry) { String os = System.getProperty("os.name"); if (os.toLowerCase().startsWith("win")) { //如果是Windows系统 registry.addResourceHandler("/img/**").addResourceLocations("file:"+windowsFilePath); }else{ //linux和mac系统 registry.addResourceHandler("/img/**").addResourceLocations("file:"+linuxFilePath+"/"); } }
测试:
本地图片地址:/Users/lhk/Desktop/zhzf/pic/123.jpg
数据库存储地址: http://ip地址:端口号/img/123.jpg
欢迎分享,转载请注明来源:内存溢出
评论列表(0条)