From eda0e41b53657db6b02ba8724e7b57c9cea7af6c Mon Sep 17 00:00:00 2001 From: Zhang Liguo <482370576@qq.com> Date: Tue, 26 Dec 2023 22:43:35 +0800 Subject: [PATCH] =?UTF-8?q?attachment=E4=BF=AE=E5=A4=8D?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../controller/AttachmentController.java | 34 ++++++++++++------- 1 file changed, 22 insertions(+), 12 deletions(-) diff --git a/src/main/java/com/lovenav/controller/AttachmentController.java b/src/main/java/com/lovenav/controller/AttachmentController.java index 504cef1..4dcc156 100644 --- a/src/main/java/com/lovenav/controller/AttachmentController.java +++ b/src/main/java/com/lovenav/controller/AttachmentController.java @@ -7,17 +7,17 @@ import com.lovenav.service.ConfigService; import org.apache.catalina.core.ApplicationContext; import org.apache.commons.io.FileUtils; import org.springframework.beans.factory.annotation.Autowired; -import org.springframework.http.HttpHeaders; -import org.springframework.http.HttpStatus; -import org.springframework.http.MediaType; -import org.springframework.http.ResponseEntity; +import org.springframework.http.*; +import org.springframework.ui.Model; import org.springframework.web.bind.annotation.*; import org.springframework.web.context.support.ServletContextResource; import org.springframework.web.multipart.MultipartFile; +import org.springframework.web.servlet.ModelAndView; import javax.annotation.Resource; import javax.imageio.ImageIO; import javax.servlet.ServletContext; +import javax.servlet.http.HttpServletRequest; import java.io.*; import java.util.HashMap; @@ -30,20 +30,30 @@ public class AttachmentController { AttachmentService attachmentService; @Autowired ConfigService configService; + + + //上传附件 - @RequestMapping("/uploadfile") - public HashMap uploadFile(MultipartFile multipartFile,String cate,Config config) throws IOException {//@RequestPart("photos") MultipartFile multipartFile + @RequestMapping(value = "/uploadfile",method = RequestMethod.POST) + public HashMap uploadFile(MultipartFile multipartFile, String cate, Config config) throws IOException {//@RequestPart("photos") MultipartFile multipartFile HashMap map=new HashMap<>(); - Long id=null; if (multipartFile==null){ map.put("msg","文件不能为空!"); return map; } - out.println(multipartFile.getOriginalFilename()); - map=attachmentService.upload(multipartFile,cate,id); - config.setValue(map.get("id")); - config.setType("image"); - map.put("msg",configService.addConfig(config)); + Config config1=configService.selectAlreadyExist(config); + if (config1==null){ + map=attachmentService.upload(multipartFile,cate); +// out.println(map.get("id")); + config.setValue(map.get("id")); + config.setType("image"); + map.put("msg",configService.addConfig(config)); + }else { + out.println(config1.getValue()); + configService.updateConfig(config1); + map=attachmentService.updateFile(multipartFile,cate,config1); + } + return map; }