Explorar el Código

图片地址拼接bug

xusonglin hace 5 años
padre
commit
9a76290968

+ 1 - 2
src/main/java/com/jkcredit/sysnews/service/newsArticle/NewsArticleServiceImpl.java

@@ -97,8 +97,7 @@ public class NewsArticleServiceImpl extends BaseService implements NewsArticleSe
         List<String> urlList = new ArrayList<>();
         for (NewsArticlePhotoPo po : newsArticlePhotoPoList) {
             PhotoVo photoVo = photoService.getPhotoById(po.getPhotoId());
-            String url = accessPath + accessResource + photoVo.getUrl().replace("/","");
-            urlList.add(url);
+            urlList.add(photoVo.getUrl());
         }
         newsArticleVo.setUrlList(urlList);
         return newsArticleVo;

+ 6 - 0
src/main/java/com/jkcredit/sysnews/service/photo/PhotoServiceImpl.java

@@ -97,10 +97,16 @@ public class PhotoServiceImpl extends BaseService implements PhotoService {
 
         try {
             UploadUtil.upload(photoDto.getPhoto(), filePath);
+
         } catch (IOException ioe) {
             log.error("图片上传失败,失败原因:{}", ioe.getMessage());
             throw new ServiceException("图片上传失败");
         }
+        File dest = new File(filePath);
+        if (!dest.getParentFile().exists()) {
+            log.error("图片上传失败,失败原因:服务器图片不存在");
+            throw new ServiceException("图片上传失败");
+        }
 
         photoDto.setUrl(File.separator + fileName);
         PhotoPo photoPo = new PhotoPo();