frontend/index无法取出图片的一种原因
来源:9-3 首页前端的开发下

如怨如慕
2020-11-15
仅供参考,不具有代表性。
先在idea中配置好tomcat
原先的PathUtil类
public class PathUtil {
private static String separator = System.getProperty("file.separator");
public static String getImgBasePath(){
String os = System.getProperty("os.name");
String basePath = "";
if (os.toLowerCase().startsWith("win")){
basePath = "F:/image/";
}else {
basePath = "/home/xiangze/image/";
}
basePath = basePath.replace("/",separator);
return basePath;
}
public static String getShopImagePath(long shopId){
String imagePath = "upload/item/shop/"+shopId+"/";
//upload前没加/,在basePath的F:/image/后加了/
return imagePath.replace("/",separator);
}
}
所以数据库里存储的相对路径全是uoload打头,而非\upload打头,取出路径后,前端无法显示。
将PathUtil的路径稍微更改一下,在数据库的相对路径upload前全部加上\
basePath = "F:/image";
String imagePath = "/upload/item/shop/"+shopId+"/";
即可正确显示。
写回答
3回答
-
sunyata5513953
2021-10-07
跟着前面学到这这卡了好久,终于在你这得到解决了,感谢🙏
00 -
慕容4479512
2021-03-28
正好遇到这个问题,感谢分享!!
00 -
翔仔
2020-11-15
赞同学的分享 ,多多分享,自己的记忆也会更深刻,加油:)
012020-11-17
相似问题