如何在JasperReports中验证空报告? [英] How to validate empty report in JasperReports?

查看:179
本文介绍了如何在JasperReports中验证空报告?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我的情况是,当我无法使用我的查询检索任何内容时,在jasper文件中找到,仍会生成报告。

My situation is when I'm not able to retrieve anything with my query, that is found inside the jasper file, a report is still generated.

我正在使用这行代码生成报告。

I'm using this line of code to generate report.

ByteArrayOutputStream baos = new ByteArrayOutputStream();

JasperPrint jasperPrint = JasperFillManager.fillReport(jasperReportStream, params, jdbcConnection);
long start = System.currentTimeMillis();
Exporter jrExporter = getJRExporter(format, jasperPrint, baos);
jrExporter.exportReport();
bytes = baos.toByteArray();

有没有办法使用导出器对象来检测我的报告是否为空?
我尝试使用byteArray验证null,然后在生成pdf格式时转换为String。

Is there a way to use the exporter object to detect if my report is empty? I have tried to validate null using the byteArray then converted to String when producing a pdf format.

然而,我无法轻易检查byteArray是否为null,因为它产生了这个输出,尽管我的查询没有返回结果:

However I cannot easily check if byteArray is null since it produces this output despite returning no results from my query:

%PDF-1.4
%����
1 0 obj <</Length 45/Filter/FlateDecode>>stream
x�3P0T�5T0P0�4�ɹ\�\N!\�f
���
!)\�!\�\\   


推荐答案

设置 jasperReport tag whenNoDataType =NoPages或删除 whenNoDataType 属性(默认为NoPages)

Set on jasperReport tag whenNoDataType="NoPages" or remove whenNoDataType attribute (default is "NoPages")

检查 JasperPrint 中有多少页面,如果 0 你有 NoData

Check how many pages there are in the JasperPrint, if 0 you have NoData

    JasperPrint print = JasperFillManager.fillReport(jasperReportStream, params, jdbcConnection);
    List<JRPrintPage> pages = print.getPages();
    if (pages.size()==0){
            //No pages, do not export instead do other stuff
    }

这篇关于如何在JasperReports中验证空报告?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆