java web水晶报表_Crytal reports水晶报表在Spring boot web项目中的使用, 无需web.xml文件, 无jsp文件...

使用jsp页面显示水晶报表还是存在这样的问题:

1.  配置麻烦。

水晶报表自身的网页版crytalviewer显示内容存在失真,和实际的不一致。

水晶报表的XML文件配置不正确导致无法加载报表文件,难以排除问题。

以下方法可以更加简单的在Spring boot 项目中使用Crytal reports.

在src\main\resources下创建lib文件夹,并在通过build path->Add Extern Achives 将水晶报表的依赖库加入到项目中。

990db43da25bdb8a3dd133d1865b9df8.png

使用CR4E (Crytal Reports for Eclipse) 提供的CRJavaHelper 灵活操作报表,例如直接用PDF文件预览,以及导出PDF,Word等操作。

7fa660a0a1a022fb3adf63adf8c9e083.png

使用@RestContorller 创建控制器,设置RequestMapper, 使用绝对路径加载报表即可

@RestController

public class ReportPOController {

@GetMapping("/Report/PO/showPdf")

public void showPdf()

throws ReportSDKExceptionBase, IOException {

ReportClientDocument reportClientDocument = new ReportClientDocument();

reportClientDocument.open("reports/ReportPO.rpt", 0);

// This will be used by the viewer to display the desired report. True to

// Download this report.

CRJavaHelper.exportPDF(reportClientDocument, response, false);

}

@GetMapping("/Report/PO/exportPdf")

public void exportPdf()throws ReportSDKExceptionBase, IOException {

ReportClientDocument reportClientDocument = new ReportClientDocument();

reportClientDocument.open("reports/ReportPO.rpt", 0);

// This will be used by the viewer to display the desired report. True to

// Download this report.

CRJavaHelper.exportPDF(reportClientDocument, response, true);

}

}

注意:我的项目中, 我在src/main/resource下创建了一个reports文件夹,所以上面的报表绝对路径为reports/ReportPO.rpt,

无需tld标签定义文件, 无需xml配置文件,也不需要加载jsp支持。

6d49283f302ab8a5ffc9ca4984597b8a.png

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值