SpringMVC Excel 가져오기
4490 단어 JavaWeb-Spring
org.apache.poi
poi-ooxml
3.5-FINAL
2. Ajax가 업로드한 excel의 기능 구현
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 = " ";
}
}
});
}
3. 파일 처리를 위한 SpringMVC controller
public static List getExcelDataFromReqeust(HttpServletRequest request,BaseBean baseBean) {
List resultList = new ArrayList<>();
List
3.1 도구 클래스 분석 excel 데이터
public static List
4. 호출하는 방법
@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;
}