JAvaデータインポートノート
1441 ワード
:
/**
*
*
* @param mapping
* @param form
* @param request
* @param response
* @return
* @throws Exception
*/
public ActionForward importData(ActionMapping mapping, ActionForm form,
HttpServletRequest request, HttpServletResponse response)
throws Exception {
DynaActionForm dynaForm = (DynaActionForm) form;
FormFile xlsFile = (FormFile) dynaForm.get("studentFile");
InputStream is = xlsFile.getInputStream();
HSSFWorkbook wb = new HSSFWorkbook(new POIFSFileSystem(is)); //
Importer importer = new DefaultEntityImporter(Student.class);
//Importer importer = new CJBStudentEntityImporter(Student.class);
importer.setReader(new ExcelItemReader(wb, 1));
if (null == importer) {
return forward(request, "/pages/components/importData/error");
}
TransferResult tr = new TransferResult();
importer.addListener(new ImporterForeignerListener(utilService))
.addListener(new StdImportListener(utilService.getUtilDao()));
importer.transfer(tr);
request.setAttribute("importer", importer);
request.setAttribute("importResult", tr);
return forward(request, "/pages/components/importData/result");
}