1. 添加依赖
org.apache.poi
poi-ooxml
3.5-FINAL
function upload() {
var uploadResult = document.getElementById("upload-result");
uploadResult.style.color = "green";
uploadResult.innerHTML = "正在上传.....";
var formData = new FormData($("uploadForm")[0]);
formData.append('Content-Type', 'multipart/form-data');
formData.append('image', $('input[type=file]')[0].files[0]);
$.ajax({
url : "${pageContext.request.contextPath}/api/v1/file",
type : 'POST',
data : formData,
dataType : 'json',
contentType : false,
processData : false,
cache : false,//防止缓存
error : function(data) {
alert("请求失败,网络异常")
console.log(data);
},
success : function(data) {
console.log(data);
var code = data.status;
if (code == 200) {
uploadResult.style.color = "green";
uploadResult.innerHTML = "上传成功";
imgUrl = data.id;
} else {
uploadResult.style.color = "red";
uploadResult.innerHTML = "上传失败";
}
}
});
}
public static List getExcelDataFromReqeust(HttpServletRequest request,BaseBean baseBean) {
List resultList = new ArrayList<>();
List
3.1 工具类解析excel 数据
public static List
@RequestMapping(value = "/excel", method = RequestMethod.POST)
@ResponseBody
public Object uploadFile(HttpServletRequest request) {
List result = ExcelImportUtil.getExcelDataFromReqeust(request,new VaccineItem());
for (BaseBean object : result) {
VaccineItem vaccineItem = (VaccineItem) object;
System.out.println(vaccineItem.toString());
}
return StatusConfig.OK;
}