后端代码:
import org.springframework.web.multipart.MultipartFile;
/**
* 文件上传
* @param file 上传的excel文件
* @return
* @throws Exception
*/
@PostMapping("/uploadExcelItems")
@CrossOrigin(allowCredentials = "true", origins = {"*"})
@ResponseBody
public ReturnResult<?> uploadExcelItems(@RequestParam("file") MultipartFile file) throws Exception{
if (file == null) {
return new ReturnResult<>().failed(ReturnCodeEnum.PARAM_ERROR.getCode(),ReturnCodeEnum.PARAM_ERROR.getDesc(),"上传文件不能为空");
}
}
前端反馈:
最终发现:
name="excel"改为name=“file” 问题解决