jasper table第一行未显示在pdf中

时间:2017-09-23 13:56:13

标签: java jasper-reports

尝试在java中生成pdf时,Jasper报告中未显示java列表的第一个数据。

MY JRXML代码:

  @RequestMapping(value = ClinicRestURIConstants.APPOINTMENTREPORT, method = RequestMethod.GET)
   public byte[] appointmentReport(HttpServletRequest request, HttpServletResponse response,@PathVariable Integer clinic_id,@PathVariable Integer branch_id,@PathVariable Integer doctor_id)
           throws JRException,IOException,DocumentException,SAXException {

       List<Appointment> appointmentList;
       appointmentList = appointmentreportservice.appReport(clinic_id,branch_id,doctor_id);

       String reportLocation ="E:\\ClinicManagementNew\\Clinic\\src\\main\\webapp\\static\\jrxml\\appointmentReport.jrxml";

       JasperReport jasperReport = JasperCompileManager.compileReport(reportLocation);

       File image = new File("E:\\ClinicManagementNew\\Clinic\\src\\main\\webapp\\static\\img\\logo.png");
       FileInputStream path = new FileInputStream(image);

       HashMap map = new HashMap();
       map.put("Image",path);

       if (jasperReport != null) {

           JasperPrint jasperPrint = JasperFillManager.fillReport(jasperReport, map, new JRBeanCollectionDataSource(appointmentList));
           response.setHeader("Content-disposition","inline; filename = Report.pdf");
           OutputStream outputStream = response.getOutputStream();

           JRPdfExporter exporter = new JRPdfExporter();
           exporter.setParameter(JRExporterParameter.JASPER_PRINT, jasperPrint);
           exporter.setParameter(JRExporterParameter.OUTPUT_STREAM, outputStream);
           exporter.exportReport();
       }
       return null;
   }

这是我的java控制器代码:

INSERT INTO `users` (`date`, `first_name`, `last_name`, `username`, `email`, `image`, `password`, `role`) VALUES (NULL, '$first_name', '$last_name', '$username', '$email', '$image', '$password', '$role');

此java列表返回两行,但pdf中只显示一行。如何显示该pdf中的第一行。

请有人帮助我解决这个问题。提前谢谢。

1 个答案:

答案 0 :(得分:0)

在Jasper工作室

  • 创建一个名为“MyDS”的参数,类型为net.sf.jasperreports.engine.data.JRBeanCollectionDataSource。 enter image description here
  • 在表格数据集中选择“不使用任何连接或数据源”,然后选择之前的“MyDS”作为REPORT_DATAS_OURCE。 enter image description here

在你的java代码中添加你的列表“appointmentList”作为参数。

map.put("MyDS",appointmentList);