使用spring hibernate将mysql表导出为ex​​cel

我试图导出数据在MySQL表中使用春季hibernateExcel。 我的excel导出后没有数据。 您的帮助将不胜感激。 这是我的代码below.Thanks提前

ExcelExport.java

@Override protected void buildExcelDocument(Map<String, Object> model, HSSFWorkbook workbook, HttpServletRequest request, HttpServletResponse response) throws Exception { @SuppressWarnings("unchecked") List<MOH> mohs = (List<MOH>) model.get("mohs"); HSSFSheet sheet = workbook.createSheet("MOH Form") HSSFRow header = sheet.createRow(0); header.createCell(0).setCellValue("ID"); header.getCell(0).setCellStyle(style); header.createCell(1).setCellValue("Data"); header.getCell(1).setCellStyle(style); int rowCount = 1; for (MOH aBook : mohs) { HSSFRow aRow = sheet.createRow(rowCount++); aRow.createCell(0).setCellValue(aBook.getSurvey_id()); aRow.createCell(1).setCellValue(aBook.getName()); 

Controller.java

 @RequestMapping(value = "/downloadExcel", method = RequestMethod.GET) public ModelAndView downloadExcel() { ModelAndView mav = new ModelAndView("showMOH"); List<MOH> mohs = new ArrayList<MOH>(); return new ModelAndView("excelView", "mohs", mohs); 

可能有更多的select给你: –
1.用hibernate你可以用Apache POI来做这个。 这里有一个带有例子的教程 ,将指导你完成整个过程。
2.您也可以使用BIRT并生成您想要的任何格式的数据库。
3.您可以使用ResultSet将数据直接从MySQL导出到Excel。 在这里看到如何将ResultSet导出到Excel 。
4.如果您使用的是struts2,则可以使用datagrid将其导出为CSV或Excel。