diff --git a/src/main/java/org/hqu/production_ms/controller/FileController.java b/src/main/java/org/hqu/production_ms/controller/FileController.java new file mode 100644 index 0000000000000000000000000000000000000000..c9fb62611fc7d56c2eba3b89708b9e2511244986 --- /dev/null +++ b/src/main/java/org/hqu/production_ms/controller/FileController.java @@ -0,0 +1,72 @@ +package org.hqu.production_ms.controller; + +import java.util.HashMap; +import java.util.Iterator; +import java.util.Map; + +import org.hqu.production_ms.service.FileService; +import org.hqu.production_ms.util.JsonUtils; +import org.springframework.beans.factory.annotation.Autowired; +import org.springframework.stereotype.Controller; +import org.springframework.web.bind.annotation.RequestMapping; +import org.springframework.web.bind.annotation.RequestMethod; +import org.springframework.web.bind.annotation.RequestParam; +import org.springframework.web.bind.annotation.ResponseBody; +import org.springframework.web.multipart.MultipartFile; +import org.springframework.web.multipart.MultipartHttpServletRequest; + +/** + * + * created on 2016年9月27日 + * + * 上传图片处理 + * + * @author megagao + * @version 0.0.1 + */ +@Controller +public class FileController { + + @Autowired + private FileService fileService; + /* + @RequestMapping("/file/upload") + @ResponseBody + public String pictureUpload(MultipartFile uploadFile) { + @SuppressWarnings("unchecked") + Map result = FileService.uploadFile(uploadFile); + //为了保证功能的兼容性,需要把Result转换成json格式的字符串。 + String json = JsonUtils.objectToJson(result); + return json; + }*/ + @RequestMapping(value="/file/upload", method=RequestMethod.POST) + @ResponseBody + public String handleFileUpload(MultipartHttpServletRequest request){ + Iterator iterator = request.getFileNames(); + String json = null; + while (iterator.hasNext()) { + String fileName = iterator.next(); + MultipartFile multipartFile = request.getFile(fileName); + /*byte[] file = multipartFile.getBytes();*/ + @SuppressWarnings("unchecked") + Map result = fileService.uploadFile(multipartFile); + + json = JsonUtils.objectToJson(result); + + } + + return json; + + } + + @RequestMapping(value="/file/delete") + @ResponseBody + public String handleFileDelete(@RequestParam String fileName){ + + fileService.deleteFile(fileName); + Map result = new HashMap(); + result.put("data", "success"); + String json = JsonUtils.objectToJson(result); + return json; + } +}