html页面:
<form id = "uploadForm" method = "post" enctype = "multipart/form-data">
<label>选择文件</label>
<input id = "file" type = "file" name = "file">
<button id = "upload" type = "button" name = "button">提交</button>
</form>
js代码:
function upload(){
var formData = new FormData;
var file = document.getElementById("file").files[0];
formData.append("file",file);
$.ajax({
type: 'post',
url: getRootPath() + '/xxxx/xxxxx',
data: formData,
dataType: "json",
cache: false,
processData: false,
contentType: false,
success: function(data){
var result = data.returnCode;
var msg = data.returnMessage;
if(result === "00"){
toastr.success("")
}
else{
toastr.waring(msg);
}
}
})
}
后端代码:
@RequestMapping(value="/xxxx",method=RequestMethod.POST,produces = MediaTYpe.XXX)
@ResponseBody
public void a(@RequestParam("file") Multipartile file){
}