MultipartFile文件或者图片上传一直为null问题

Excel文件上传发现MultipartFile为空

@RequestMapping(value = "export", method=RequestMethod.POST)  
   @ResponseBody  
   public void exportFile(@RequestParam(value="file",required=false)MultipartFile myFile,HttpServletResponse response,HttpServletRequest request)throws IOException {  
        ImportExcelUtil util = new ImportExcelUtil();  
        InputStream input = null;  
        List<List<Object>> lists = null;  
        if (myFile.isEmpty()) {  
            logBefore(logger, "导入文件为空,请先添加Excel文件!");  
        }
}

jsp代码

<form action="orderExcel/export.do" name="Form" id="Form" method="post" enctype="multipart/form-data">
		<table id="table_report" class="table table-striped table-bordered table-hover">
			<tr>
				<td style="width:70px;text-align: right;padding-top: 13px;">选择Excel:</td>
				<td><input id="uploadFile" name="file" type="file" style="width:330px" onchange="fileType(this)"/><br/><br/>  
				</td>
			</tr>
			 <tr>
				<td style="text-align: center;" colspan="10">
					<input id="btnImportSubmit" class="btn btn-small btn-success" type="submit" value="Excel转换"/>
				</td>
			</tr>
		</table>
</form>

发现@RequestParam(value="file",required=false)MultipartFile myFile,value值需要和

<input id="uploadFile" name="file" type="file" style="width:330px" onchange="fileType(this)"/>
里面的name值一样,这样问题就解决了。

猜你喜欢

转载自blog.csdn.net/qq_36135335/article/details/80703556