花费太多时间在jsp上加载报告,而不是在下载Excel(POI)时

时间:2019-05-09 10:39:50

标签: java spring hibernate spring-mvc jsp

我想在report.jsp页面上获得一份报告,但这需要花费很多时间,当我使用Apache POI下载(Excel)时,只需几秒钟。

我已经尝试过以下代码,

@RequestMapping(value = "/report")
public String ivrRouteReport(Model model,
@RequestParam(value="startDate", required = false) String startDate,
@RequestParam(value="endDate", required = false) String endDate) {
          model.addAttribute("listReport",serviceInterface.getAllReportResponceBetweenDate(startDate,endDate));
  return "admin/report";
}

下载代码为

@RequestMapping(value="/reportDownload", method = {RequestMethod.POST })
public ModelAndView download(Model model,
        @RequestParam(value="startDate", required = false) String startDate,
        @RequestParam(value="endDate", required = false) String endDate
        ) {
    ModelAndView modelAndView = new ModelAndView("excelReportSummary","reportList", 
                serviceInterface.getAllReportResponceBetweenDate(startDate,endDate));
    return modelAndView;
}

两个Controller方法都继承相同的DaoImpl方法,

    @Override
public List<Report> getAllReportResponceBetweenDate(String startDate, String endDate) {
    String strqry= "SELECT c.caller_id_number as caller_id_number, c.destination_number as destination_number,"
            +" c.created_time as created_time, vbDtmf.digit as dtmf FROM VoiceBroadcastDTMF vbDtmf "
            +"LEFT JOIN cdr c ON vbDtmf.uuid=c.orig_id where (c.created_time BETWEEN '"+startDate+"%' AND '"+endDate+"%') ORDER
              BY c.created_time DESC";

    Query query = getSession().createSQLQuery(strqry)
             .addScalar("caller_id_number", new StringType())
             .addScalar("destination_number", new StringType())
             .addScalar("created_time", new StringType())
             .addScalar("dtmf", new StringType())
            .setResultTransformer(Transformers.aliasToBean(Report.class));
     List<Report> reportList =(List<Report>) query.getResultList();
     getSession().flush();
    return reportList;
}

那么,为什么报表控制器方法要花费太多时间才能在jsp上加载数据,而下载仅花费几分钟?这里我使用的是Mysql,它的表大约有50K数据。

谢谢。

0 个答案:

没有答案