data = getMaps();JRDataSource"> 跳转到主内容
websoft网络软件专家 - 深耕网络技术,打造实用软件!

解析spring boot与ireport 整合问题

pom 文件依赖net.sf.jasperreportsjasperreports6.10.0org.codehaus.groovygroovy-all2.4.11cn.lesperiTextAsian3.0controller@GetMapping("/preview") public void print(HttpServletResponse response) throws Exception {List> data = getMaps();JRDataSource dataSource = new JRBeanCollectionDataSource(data);File file = ResourceUtils.getFile("classpath:jaspertemplate/abc.jrxml");response.setCharacterEncoding("utf-8");response.setContentType("application/pdf");response.setHeader("content-disposition", "attachment;filename=" + URLEncoder.encode("test", "UTF-8") + ".pdf");

try (OutputStream outputStream = response.getOutputStream()) {//编译jrxml JasperReport jasperReport = JasperCompileManager.compileReport(file.getPath());//渲染加载数据HashMap params = new HashMap<>();JasperPrint jasperPrint = JasperFillManager.fillReport(jasperReport, params, dataSource);JasperExportManager.exportReportToPdfStream(jasperPrint, outputStream);} catch (IOException | JRException e) {e.printStackTrace();}}private List> getMaps() {List> data = new ArrayList<>();for (int i = 0; i < 10; i++) {Map m = new HashMap<>(3);m.put("id", "id" + i);m.put("name", "测试" + i);m.put("price", "price" + i);m.put("volTitle", "测试" + i);data.add(m);}return data;}

abc.jrxml 文件path:src/main/resources/jaspertemplate<band height="75" splitType="Stretch"><staticText><reportElement x="202" y="23" width="381" height="43" uuid="6dd7ca27-e8c4-4b52-964d-69045be9bf66"/><textElement textAlignment="Center" verticalAlignment="Middle"><font size="24" isBold="true" pdfFontName="STSong-Light" pdfEncoding="UniGB-UCS2-H" isPdfEmbedded="true"/></textElement><text><![CDATA[目 录]]></text></staticText></band>

其他本文不涉及有关ireport报表如何设计问题,有需要请自行查询 Y(_)Y到此这篇关于spring boot 与 ireport 整合的文章就介绍到这了,更多相关spring boot ireport 整合内容请搜索脚本之家以前的文章或继续浏览下面的相关文章希望大家以后多多支持脚本之家!

您可能感兴趣的文章:ireport数据表格报表的简单使用iReport使用教程(示例教程)

关于解决iReport4.1.1无法正常启动或者闪退或者JDK8不兼容的问题

相关文章