From b3631dd074d7fa5520f7afcf2cdc1ab681700e7c Mon Sep 17 00:00:00 2001 From: heheng <heheng@123456> Date: 星期四, 21 十一月 2024 17:18:15 +0800 Subject: [PATCH] 部分修改 --- expert-admin/src/main/java/com/gkhy/web/controller/common/CommonController.java | 25 +++++++++++++++++++++---- 1 files changed, 21 insertions(+), 4 deletions(-) diff --git a/expert-admin/src/main/java/com/gkhy/web/controller/common/CommonController.java b/expert-admin/src/main/java/com/gkhy/web/controller/common/CommonController.java index be5d96a..c5c70eb 100644 --- a/expert-admin/src/main/java/com/gkhy/web/controller/common/CommonController.java +++ b/expert-admin/src/main/java/com/gkhy/web/controller/common/CommonController.java @@ -5,6 +5,7 @@ import com.gkhy.common.config.ExpertConfig; import com.gkhy.common.constant.Constants; import com.gkhy.common.core.domain.AjaxResult; +import com.gkhy.common.exception.ServiceException; import com.gkhy.common.utils.StringUtils; import com.gkhy.common.utils.file.FileUploadUtils; import com.gkhy.common.utils.file.FileUtils; @@ -15,14 +16,12 @@ import org.slf4j.LoggerFactory; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.http.MediaType; -import org.springframework.web.bind.annotation.GetMapping; -import org.springframework.web.bind.annotation.PostMapping; -import org.springframework.web.bind.annotation.RequestMapping; -import org.springframework.web.bind.annotation.RestController; +import org.springframework.web.bind.annotation.*; import org.springframework.web.multipart.MultipartFile; import javax.servlet.http.HttpServletRequest; import javax.servlet.http.HttpServletResponse; +import java.io.File; import java.util.ArrayList; import java.util.List; @@ -172,4 +171,22 @@ log.error("下载文件失败", e); } } + + + @ApiOperation(value = "删除附件") + @DeleteMapping("/removeFile") + public void removeFile(@RequestParam(required = true) String path){ + // 本地资源路径 + String localPath = ExpertConfig.getProfile(); + // 数据库资源地址 + String deletePath = localPath + path; + File dirFile=new File(deletePath); + if(!dirFile.exists()){ + throw new ServiceException("文件不存在"); + } + if(!dirFile.isFile()){ + throw new ServiceException("非文件,不能删除"); + } + dirFile.delete(); + } } -- Gitblit v1.9.2