解析spring boot与ireport 整合问题
作者:小方同学_ 发布时间:2021-12-15 17:49:25
标签:spring,boot,ireport,整合
pom 文件依赖
<dependency>
<groupId>net.sf.jasperreports</groupId>
<artifactId>jasperreports</artifactId>
<version>6.10.0</version>
</dependency>
<dependency>
<groupId>org.codehaus.groovy</groupId>
<artifactId>groovy-all</artifactId>
<version>2.4.11</version>
</dependency>
<!-- https://mvnrepository.com/artifact/cn.lesper/iTextAsian -->
<!-- 解决中文字体显示问题 -->
<dependency>
<groupId>cn.lesper</groupId>
<artifactId>iTextAsian</artifactId>
<version>3.0</version>
</dependency>
controller
@GetMapping("/preview")
public void print(HttpServletResponse response) throws Exception {
List<Map<String, String>> 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<String, Object> params = new HashMap<>();
JasperPrint jasperPrint = JasperFillManager.fillReport(jasperReport, params, dataSource);
JasperExportManager.exportReportToPdfStream(jasperPrint, outputStream);
} catch (IOException | JRException e) {
e.printStackTrace();
}
}
private List<Map<String, String>> getMaps() {
List<Map<String, String>> data = new ArrayList<>();
for (int i = 0; i < 10; i++) {
Map<String, String> 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
<?xml version="1.0" encoding="UTF-8"?>
<jasperReport xmlns="http://jasperreports.sourceforge.net/jasperreports" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://jasperreports.sourceforge.net/jasperreports http://jasperreports.sourceforge.net/xsd/jasperreport.xsd" name="会计案卷目录" pageWidth="842" pageHeight="595" orientation="Landscape" columnWidth="782" leftMargin="30" rightMargin="30" topMargin="20" bottomMargin="20" uuid="69efba03-3736-408b-be3f-6295cabbbdfa">
<property name="ireport.zoom" value="1.2078825000000022"/>
<property name="ireport.x" value="48"/>
<property name="ireport.y" value="0"/>
<field name="volumnSeq" class="java.lang.String">
<fieldDescription><![CDATA[volumnSeq]]></fieldDescription>
</field>
<field name="ajLb" class="java.lang.String">
<fieldDescription><![CDATA[ajLb]]></fieldDescription>
</field>
<field name="volTitle" class="java.lang.String">
<fieldDescription><![CDATA[volTitle]]></fieldDescription>
</field>
<field name="bgnDate" class="java.lang.String"/>
<field name="fnshDate" class="java.lang.String"/>
<field name="keepCode" class="java.lang.String">
<fieldDescription><![CDATA[keepCode]]></fieldDescription>
</field>
<field name="docNmbr" class="java.lang.String">
<fieldDescription><![CDATA[pageNmbr]]></fieldDescription>
</field>
<field name="remark" class="java.lang.String">
<fieldDescription><![CDATA[remark]]></fieldDescription>
</field>
<field name="catalogNo" class="java.lang.String"/>
<background>
<band splitType="Stretch"/>
</background>
<title>
<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>
</title>
<columnHeader>
<band height="35" splitType="Stretch">
<staticText>
<reportElement x="9" y="0" width="61" height="35" uuid="2f94f55b-9760-4417-95b0-99e91d5aac6f"/>
<box>
<pen lineWidth="1.0" lineColor="#FF3333"/>
<topPen lineWidth="1.0" lineColor="#FF3333"/>
<leftPen lineWidth="1.0" lineColor="#FF3333"/>
<bottomPen lineWidth="1.0" lineColor="#FF3333"/>
<rightPen lineWidth="0.0" lineColor="#FF3333"/>
</box>
<textElement textAlignment="Center" verticalAlignment="Middle">
<font size="12" pdfFontName="STSong-Light" pdfEncoding="UniGB-UCS2-H" isPdfEmbedded="true"/>
</textElement>
<text><![CDATA[顺序号]]></text>
</staticText>
<staticText>
<reportElement x="70" y="0" width="68" height="35" uuid="bef549c0-dc52-41f1-b291-f515a6337a7c"/>
<box>
<pen lineWidth="1.0" lineColor="#FF3333"/>
<topPen lineWidth="1.0" lineColor="#FF3333"/>
<leftPen lineWidth="1.0" lineColor="#FF3333"/>
<bottomPen lineWidth="1.0" lineColor="#FF3333"/>
<rightPen lineWidth="0.0" lineColor="#FF3333"/>
</box>
<textElement textAlignment="Center" verticalAlignment="Middle">
<font size="12" pdfFontName="STSong-Light" pdfEncoding="UniGB-UCS2-H" isPdfEmbedded="true"/>
</textElement>
<text><![CDATA[类别]]></text>
</staticText>
<staticText>
<reportElement x="138" y="0" width="360" height="35" uuid="98ac28b1-101a-43ae-a838-1fbe3edaae7c"/>
<box>
<pen lineWidth="1.0" lineStyle="Solid" lineColor="#FF3333"/>
<topPen lineWidth="1.0" lineStyle="Solid" lineColor="#FF3333"/>
<leftPen lineWidth="1.0"/>
<bottomPen lineWidth="1.0" lineStyle="Solid" lineColor="#FF3333"/>
<rightPen lineWidth="0.0"/>
</box>
<textElement textAlignment="Center" verticalAlignment="Middle">
<font size="12" pdfFontName="STSong-Light" pdfEncoding="UniGB-UCS2-H" isPdfEmbedded="true"/>
</textElement>
<text><![CDATA[标题]]></text>
</staticText>
<staticText>
<reportElement x="498" y="0" width="100" height="35" uuid="b72ae79e-9c50-4e0f-b7fe-a0baeabc75d6"/>
<box>
<pen lineWidth="1.0" lineColor="#000000"/>
<topPen lineStyle="Solid" lineColor="#FF3333"/>
<leftPen lineStyle="Solid" lineColor="#FF3333"/>
<bottomPen lineStyle="Solid" lineColor="#FF3333"/>
<rightPen lineWidth="0.0" lineStyle="Solid" lineColor="#FF3333"/>
</box>
<textElement textAlignment="Center" verticalAlignment="Middle">
<font size="12" pdfFontName="STSong-Light" pdfEncoding="UniGB-UCS2-H" isPdfEmbedded="true"/>
</textElement>
<text><![CDATA[起止时间]]></text>
</staticText>
<staticText>
<reportElement x="598" y="0" width="54" height="35" uuid="ef0be213-7372-4f63-85d0-11b0c68db41e"/>
<box>
<topPen lineWidth="1.0" lineColor="#FF3333"/>
<leftPen lineWidth="1.0" lineColor="#FF3333"/>
<bottomPen lineWidth="1.0" lineColor="#FF3333"/>
<rightPen lineWidth="1.0" lineStyle="Solid" lineColor="#FF3333"/>
</box>
<textElement textAlignment="Center" verticalAlignment="Middle">
<font size="12" pdfFontName="STSong-Light" pdfEncoding="UniGB-UCS2-H" isPdfEmbedded="true"/>
</textElement>
<text><![CDATA[保管期限]]></text>
</staticText>
<staticText>
<reportElement x="653" y="0" width="50" height="35" uuid="c2940de1-cdba-4a39-b2d1-537c3d245c2a"/>
<box>
<topPen lineWidth="1.0" lineColor="#FF3333"/>
<bottomPen lineWidth="1.0" lineColor="#FF3333"/>
</box>
<textElement textAlignment="Center" verticalAlignment="Middle">
<font size="12" pdfFontName="STSong-Light" pdfEncoding="UniGB-UCS2-H" isPdfEmbedded="true"/>
</textElement>
<text><![CDATA[张数]]></text>
</staticText>
<staticText>
<reportElement x="703" y="0" width="63" height="35" uuid="42adecdf-1d7c-4485-b389-88a99a16da24"/>
<box>
<topPen lineWidth="1.0" lineColor="#FF3333"/>
<leftPen lineWidth="1.0" lineColor="#FF3333"/>
<bottomPen lineWidth="1.0" lineColor="#FF3333"/>
<rightPen lineWidth="1.0" lineColor="#FF3333"/>
</box>
<textElement textAlignment="Center" verticalAlignment="Middle">
<font size="12" pdfFontName="STSong-Light" pdfEncoding="UniGB-UCS2-H" isPdfEmbedded="true"/>
</textElement>
<text><![CDATA[备 注]]></text>
</staticText>
</band>
</columnHeader>
<detail>
<band height="40" splitType="Stretch">
<textField isBlankWhenNull="true">
<reportElement x="9" y="0" width="61" height="40" uuid="2daafeea-13c0-4ec3-919d-0409c5723171"/>
<box>
<pen lineWidth="1.0" lineColor="#FF3333"/>
<topPen lineWidth="0.0"/>
<leftPen lineWidth="1.0" lineColor="#FF3333"/>
<bottomPen lineWidth="1.0" lineColor="#FF3333"/>
<rightPen lineWidth="0.0"/>
</box>
<textElement textAlignment="Center" verticalAlignment="Middle">
<font size="12" pdfFontName="STSong-Light" pdfEncoding="UniGB-UCS2-H" isPdfEmbedded="true"/>
</textElement>
<textFieldExpression><![CDATA[$F{volumnSeq}]]></textFieldExpression>
</textField>
<textField isBlankWhenNull="true">
<reportElement x="70" y="0" width="68" height="40" uuid="0ff74e34-785d-482f-a67a-72a66635bcc2"/>
<box>
<pen lineWidth="1.0"/>
<topPen lineWidth="0.0" lineColor="#FF3333"/>
<leftPen lineWidth="1.0" lineColor="#FF3333"/>
<bottomPen lineWidth="1.0" lineColor="#FF3333"/>
<rightPen lineWidth="0.0" lineColor="#FF3333"/>
</box>
<textElement textAlignment="Center" verticalAlignment="Middle">
<font size="12" pdfFontName="STSong-Light" pdfEncoding="UniGB-UCS2-H" isPdfEmbedded="true"/>
</textElement>
<textFieldExpression><![CDATA[$F{ajLb}]]></textFieldExpression>
</textField>
<textField isBlankWhenNull="true">
<reportElement x="138" y="0" width="360" height="40" uuid="88d06173-5259-4897-895d-a39434e079f2"/>
<box>
<topPen lineWidth="1.0" lineColor="#FF3333"/>
<leftPen lineWidth="1.0" lineColor="#FF3333"/>
<bottomPen lineWidth="1.0" lineColor="#FF3333"/>
<rightPen lineWidth="1.0" lineColor="#FF3333"/>
</box>
<textElement textAlignment="Justified" verticalAlignment="Middle">
<font size="12" pdfFontName="STSong-Light" pdfEncoding="UniGB-UCS2-H" isPdfEmbedded="true"/>
</textElement>
<textFieldExpression><![CDATA[$F{volTitle}]]></textFieldExpression>
</textField>
<textField isBlankWhenNull="true">
<reportElement x="525" y="0" width="70" height="20" uuid="45d93afa-bd67-4f27-a3e1-c301e84ed0ea"/>
<box>
<bottomPen lineWidth="0.0"/>
</box>
<textElement textAlignment="Center" verticalAlignment="Middle">
<font size="12" pdfFontName="STSong-Light" pdfEncoding="UniGB-UCS2-H" isPdfEmbedded="true"/>
</textElement>
<textFieldExpression><![CDATA[$F{bgnDate}]]></textFieldExpression>
</textField>
<textField isBlankWhenNull="true">
<reportElement x="652" y="0" width="50" height="40" uuid="3e13e790-2e18-4154-8331-ee2ab0b8f8ad"/>
<box>
<leftPen lineWidth="1.0" lineColor="#FF3333"/>
<bottomPen lineWidth="1.0" lineColor="#FF3333"/>
</box>
<textElement textAlignment="Center" verticalAlignment="Middle">
<font size="12" pdfFontName="STSong-Light" pdfEncoding="UniGB-UCS2-H" isPdfEmbedded="true"/>
</textElement>
<textFieldExpression><![CDATA[$F{docNmbr}]]></textFieldExpression>
</textField>
<textField isBlankWhenNull="true">
<reportElement x="525" y="20" width="73" height="20" uuid="b07739c0-f452-4a53-b104-e281f40c6133"/>
<box>
<pen lineColor="#FF3333"/>
<topPen lineColor="#FF3333"/>
<leftPen lineColor="#FF3333"/>
<bottomPen lineWidth="1.0" lineColor="#FF3333"/>
<rightPen lineColor="#FF3333"/>
</box>
<textElement textAlignment="Center" verticalAlignment="Middle">
<font size="12" pdfFontName="STSong-Light" pdfEncoding="UniGB-UCS2-H" isPdfEmbedded="true"/>
</textElement>
<textFieldExpression><![CDATA[$F{fnshDate}]]></textFieldExpression>
</textField>
<staticText>
<reportElement x="498" y="0" width="30" height="20" uuid="d81412e7-1078-444a-90f4-e038ac6f30af"/>
<box>
<leftPen lineWidth="1.0" lineColor="#FF3333"/>
<bottomPen lineWidth="0.0"/>
</box>
<textElement textAlignment="Center" verticalAlignment="Middle">
<font size="12" pdfFontName="STSong-Light" pdfEncoding="UniGB-UCS2-H" isPdfEmbedded="true"/>
</textElement>
<text><![CDATA[自]]></text>
</staticText>
<staticText>
<reportElement x="498" y="20" width="30" height="20" uuid="474ba566-24b3-4681-baf7-21d9647771d9"/>
<box>
<leftPen lineWidth="1.0" lineColor="#FF3333"/>
<bottomPen lineWidth="1.0" lineColor="#FF3333"/>
</box>
<textElement textAlignment="Center" verticalAlignment="Middle">
<font size="12" pdfFontName="STSong-Light" pdfEncoding="UniGB-UCS2-H" isPdfEmbedded="true"/>
</textElement>
<text><![CDATA[至]]></text>
</staticText>
<textField isBlankWhenNull="true">
<reportElement x="703" y="0" width="63" height="40" uuid="0cab3c98-0f59-42c4-920b-118f942bcbb9"/>
<box>
<leftPen lineWidth="1.0" lineColor="#FF3333"/>
<bottomPen lineWidth="1.0" lineStyle="Solid" lineColor="#FF3333"/>
<rightPen lineWidth="1.0" lineStyle="Solid" lineColor="#FF3333"/>
</box>
<textElement textAlignment="Center" verticalAlignment="Middle">
<font size="12" pdfFontName="STSong-Light" pdfEncoding="UniGB-UCS2-H" isPdfEmbedded="true"/>
</textElement>
<textFieldExpression><![CDATA[$F{remark}]]></textFieldExpression>
</textField>
<textField isBlankWhenNull="true">
<reportElement x="598" y="0" width="54" height="40" uuid="79eb3d06-f603-45b1-aa89-f8713daf6473"/>
<box>
<leftPen lineWidth="1.0" lineColor="#FF3333"/>
<bottomPen lineWidth="1.0" lineColor="#FF3333"/>
</box>
<textElement textAlignment="Center" verticalAlignment="Middle">
<font size="12" pdfFontName="STSong-Light" pdfEncoding="UniGB-UCS2-H" isPdfEmbedded="true"/>
</textElement>
<textFieldExpression><![CDATA[$F{keepCode}]]></textFieldExpression>
</textField>
</band>
</detail>
<pageFooter>
<band height="45" splitType="Stretch"/>
</pageFooter>
</jasperReport>
其他
本文不涉及有关ireport报表如何设计问题,有需要请自行查询 Y(_)Y
来源:https://blog.csdn.net/junoohoome/article/details/115913261


猜你喜欢
- 相信大家对 String 和 StringBuffer 的区别也已经很了解了,但是估计还是会有很多同志对这两个类的工作原理有些不清楚的地方,
- 本文实例为大家分享了android实现简易计算器展示的具体代码,供大家参考,具体内容如下效果图:一、如图,首先布局计算器主页显示activi
- C#是一门面向对象的语言,具有面向对象的基本特征,抽象、封装、继承、多态等性质。学习C#除了一些基本的语法,还得学习一些新的特性,比如说:泛
- Spring 基于注解启动主要有两个Class实现注解启动AnnotationConfigApplicationContextAnnotat
- springboottest测试依赖和使用<dependency> <groupId>or
- Redis缓存中间件缓存是什么  所谓缓存就是数据交换的缓冲区(称作Cache [ k&aeli
- 本文将介绍一段实例代码,来讲解利用正则表达式使C#判断输入日期格式是否正确的方法。希望这段代码能对大家有所帮助。 通常我们在用C#
- HttpClient使用post方法提交数据 源代码:package post;import Java.io.IOException;imp
- 在ios7中,苹果的原生态应用几乎都能够通过向右滑动来返回到前一个页面,这样可以避免用户在单手操作时用大拇指去点击那个遥远的返回键(ipho
- 简介AppCDS的全称是Application Class-Data Sharing。主要是用来在不同的JVM中共享Class-Data信息
- 先上结论RPC请求的效率是HTTP请求的1.6倍左右,性能明显比HTTP请求要高很多。原因分析RESTful是基于HTTP协议进行交互的,H
- 泛型是 2.0 版 C# 语言和公共语言运行库 (CLR) 中的一个新功能。泛型将类型参数的概念引入 .NET Framework,类型参数
- 我也不知道这个叫什么,就是比如我要打开我电脑的计算机,可以直接在命令行输入“calc”就可以了。现在用让代码去执行。public stati
- 一、技术概述1、描述这个技术是做什么?是Unity一套网络工具库,用于进行Http请求2、学习该技术的原因?项目需要,防止使用C#原生的网络
- 前言Android 开发中,我们经常需要实现图片的圆形/圆角的效果,我们可以使用两种方式来实现这样的效果。一种是使用Xfermode,另一种
- 一、整合原理二、导包(41个)1.hibernate(1)hibernate/lib/required(2)hibernate/lib/jp
- 什么是异步调用?异步调用是相对于同步调用而言的,同步调用是指程序按预定顺序一步步执行,每一步必须等到上一步执行完后才能执行,异步调用则无需等
- 这里给一个样例树:代码:#include <stdio.h> #include <string.h>#include
- 本文实例总结了C# XML序列化方法及常用特性。分享给大家供大家参考,具体如下:C#对象XML序列化(一):序列化方法和常用特性.Net F
- 如:string str1 = "This is a test";string str2 = "This-is