首页 > Web开发 > 详细

JasperReport

时间:2020-03-13 22:38:46      阅读:62      评论:0      收藏:0      [点我收藏+]
  • 坐标
    • <dependency>
      <groupId>net.sf.jasperreports</groupId>
      <artifactId>jasperreports</artifactId>
      <version>6.8.0</version>
      </dependency>
  • jasper原理
    • 技术分享图片
    • Exporter: 报表输出的管理类,用于管理输出报表的格式
  • java类
    • //导出运营数据到pdf并提供客户端下载

      @RequestMapping("/exportBusinessReport4PDF")

      public Result exportBusinessReport4PDF(HttpServletRequest request,

      HttpServletResponse response) {

      try {

      Map<String, Object> result = reportService.getBusinessReportData();

      //取出返回结果数据,准备将报表数据写入到PDF文件中

      List<Map> hotSetmeal = (List<Map>) result.get("hotSetmeal");

      //动态获取模板文件绝对磁盘路径

      String jrxmlPath =

      request.getSession().getServletContext().getRealPath("template") +

      File.separator + "health_business3.jrxml";

      String jasperPath =

      request.getSession().getServletContext().getRealPath("template") +

      File.separator + "health_business3.jasper";

      //编译模板

      JasperCompileManager.compileReportToFile(jrxmlPath, jasperPath);

      //填充数据---使用JavaBean数据源方式填充

      JasperPrint jasperPrint =

      JasperFillManager.fillReport(jasperPath,result,

      new

      JRBeanCollectionDataSource(hotSetmeal));

      ServletOutputStream out = response.getOutputStream();

      response.setContentType("application/pdf");

      response.setHeader("content-Disposition",

      "attachment;filename=report.pdf");

      //输出文件

      JasperExportManager.exportReportToPdfStream(jasperPrint,out);

      return null;

      } catch (Exception e) {

      e.printStackTrace();

      return new Result(false, MessageConstant.GET_BUSINESS_REPORT_FAIL);

      }

      }

JasperReport

原文:https://www.cnblogs.com/shangyunlin/p/12489241.html

(0)
(0)
   
举报
评论 一句话评论(0
关于我们 - 联系我们 - 留言反馈 - 联系我们:wmxa8@hotmail.com
© 2014 bubuko.com 版权所有
打开技术之扣,分享程序人生!