<body>
<input type=”file” id=”importFile”/>
<input type=”button” id=”import-submit” value=”提交导入文件”/>
</body>
<script type=”text/javascript”>
$(‘#import-submit’).click(function () {
var formData = new FormData();
var name = $(“#importFile”).val();
formData.append(‘file’, $(“#importFile”)[0].files[0]);
// 此处可传入多个参数
formData.append(‘name’, name);
$.ajax({
url: ‘/collar/import’,
type: ‘post’,
async: false,
data: formData,
processData: false,// 告诉jQuery不要去处理发送的数据
contentType: false,// 告诉jQuery不要去设置Content-Type请求头
beforeSend: function () {//过程…
console.log(‘正在进行,请稍候’)
},
success: function (res) {
if (+res === ’01’) {
console.log(‘导入成功’)
} else {
console.log(‘导入失败’)
}
},
error:function(){
console.log(‘导入失败’)
}
})
})
</script>
@RequestMapping(“/import”)
public void export(VivoIMEIUp zipRequest, @RequestParam(“file”) MultipartFile file,
HttpServletRequest request, HttpServletResponse response) {
//通过file.getInputStream();处理
}
原文:https://blog.csdn.net/weixin_43992507/article/details/85091642