Browse Source

批量导入增加文件上传是否为空判断

hejq 7 years ago
parent
commit
87a8dbace5

+ 7 - 2
src/main/java/com/uas/platform/b2c/trade/order/controller/PurchaseProductController.java

@@ -17,6 +17,7 @@ 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.RestController;
+import org.springframework.web.multipart.commons.CommonsMultipartFile;
 import org.springframework.web.servlet.ModelAndView;
 
 import javax.servlet.http.HttpServletRequest;
@@ -68,13 +69,17 @@ public class PurchaseProductController {
      */
     @RequestMapping(value = "/personal/release/excel", method = RequestMethod.POST)
     public ResultMap releasePersonalProductByExcel(FileUpload uploadItem, Integer ignoreImport) {
-        String fileName = uploadItem.getFile().getOriginalFilename();
+        CommonsMultipartFile file = uploadItem.getFile();
+        if (null == file) {
+            return ResultMap.error(new IllegalOperatorException("请上传excel文件"));
+        }
+        String fileName = file.getOriginalFilename();
         // 获取EXCEL后缀格式
         String suffix = fileName.substring(fileName.lastIndexOf(".") + 1);
         InputStream inputStream;
         Workbook workbook;
         try {
-            inputStream = uploadItem.getFile().getInputStream();
+            inputStream = file.getInputStream();
             // 根据表格格式分开处理
             if (JxlsExcelView.EXCEL_XLS.equals(suffix)) {
                 workbook = new HSSFWorkbook(inputStream);