controller
@RequestMapping(value = "/import/index", method = RequestMethod.POST) @ResponseBody public ResponseResult upload(HttpServletRequest request,@RequestParam(value="file", required=true) MultipartFile file) { ResponseResult<Object> responseResult = new ResponseResult<>(); //判断文件是否为空 if(file == null) { responseResult.setSuccess(false); responseResult.setErrorMessage("文件为空"); return responseResult; } //获取文件名 String name = file.getOriginalFilename(); //进一步判断文件是否为空(即判断其大小是否为0或其名称是否为null) long size = file.getSize(); if(name == null || ("").equals(name) && size == 0) { responseResult.setSuccess(false); responseResult.setErrorMessage("null"); return responseResult; } Map<String, Integer> dataMap = new HashMap<>(); try { //批量导入。参数:文件名,文件。 dataMap = goodsService.batchImport(name, file); }catch (Exception e){ e.printStackTrace(); responseResult.setSuccess(false); responseResult.setErrorMessage("批量导入XX异常!"); } responseResult.setSuccess(true); responseResult.setData(dataMap); responseResult.setErrorMessage("批量导入EXCEL成功!"); return responseResult; }util
/** * 读EXCEL文件,获取客户信息集合 * @param *