丟失請求引數 問題解決
阿新 • • 發佈:2018-12-16
在from表單裡面添加了上傳附件的程式碼
<tr> <td height="50" width="15%" align="center">上傳檔案</td> <td width="35%" valign="middle"> <div class="upload" style="position: relative;"> <!-- <input type="file" name="multipartfile" id="textfield" class="validate[required,funcCall[judgeFileType]] upload_input"> --> <input type="file" name="multipartfile" id="multipartfile" class="upload_input"> <div class="upload_text"></div> <div class="upload_text_a"></div> <a class="upload_btn" href="javascript:;">上傳</a> <a class="upload_delete" href="javascript:;"></a> </div> </td> </tr>
後臺如下編寫,在前臺沒有新增附件,結果提交表單到後臺時,一直提示“丟失請求引數”
@RequestMapping(value = "/saveRecord", method = RequestMethod.POST, produces = "application/json; charset=utf-8")
public AjaxMessage saveRecord(@RequestParam("multipartfile") MultipartFile multipartfile) {
//.....
}
很鬱悶,網上好多說是Spring的配置問題,但是改了配置還是不能解決,把後臺程式碼改成下面這樣,解決了。如果添加了附件,在multipartfile裡面會有,如果沒有新增附件,在陣列為空
@RequestMapping(value = "/saveRecord", method = RequestMethod.POST, produces = "application/json; charset=utf-8")
public AjaxMessage saveRecord(@RequestParam("multipartfile") MultipartFile[] multipartfile) {
//....
}