- html - 出于某种原因,IE8 对我的 Sass 文件中继承的 html5 CSS 不友好?
- JMeter 在响应断言中使用 span 标签的问题
- html - 在 :hover and :active? 上具有不同效果的 CSS 动画
- html - 相对于居中的 html 内容固定的 CSS 重复背景?
我正在创建一个 jasper 报告,其中包含标题和元素列表。我通过 JRBeanCollectionDataSource 将自定义对象的数组列表传递给 jasper 报告我已使用列表组件。但它总是返回空字段,尽管我在列表中有数据。
这是我的 Bean 类:
public class Medicine {
private String medicineName;
private String schedule;
private String date;
private String hour;
private String dosage;
private String taken;
public String getMedicineName() {
return medicineName;
}
public void setMedicineName(String medicineName) {
this.medicineName = medicineName;
}
public String getSchedule() {
return schedule;
}
public void setSchedule(String schedule) {
this.schedule = schedule;
}
public String getDate() {
return date;
}
public void setDate(String date) {
this.date = date;
}
public String getHour() {
return hour;
}
public void setHour(String hour) {
this.hour = hour;
}
public String getDosage() {
return dosage;
}
public void setDosage(String dosage) {
this.dosage = dosage;
}
public String getTaken() {
return taken;
}
public void setTaken(String taken) {
this.taken = taken;
}
}
这就是我发送数据进行报告的方式。
try {
ClassLoader classLoader = getClass().getClassLoader();
File file = new File(classLoader.getResource("reports/medipost.jrxml").getFile());
JasperReport jasperReport = JasperCompileManager
.compileReport(file.getAbsolutePath());
MediPostDAO mediPostDAO = new MediPostDAO();
Map<String, Object> parameters = mediPostDAO.getMedipostData(id);
List<Medicine> medicineList = new MedicineDAO().getMedicineList(id);
JRBeanCollectionDataSource ds = new JRBeanCollectionDataSource(medicineList);
JasperPrint jasperPrint = JasperFillManager.fillReport(jasperReport,
parameters, ds);
try {
JasperExportManager.exportReportToPdfStream(jasperPrint, response.getOutputStream());
response.setContentType("application/pdf");
} catch (IOException e) {
e.printStackTrace();
}
} catch (JRException e) {
e.printStackTrace();
}
这是一个 jrxml
<?xml version="1.0" encoding="UTF-8"?>
<!-- Created with Jaspersoft Studio version 6.2.1.final using JasperReports Library version 6.2.1 -->
<!-- 2016-04-20T18:08:25 -->
<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="Blank_A4" pageWidth="595" pageHeight="842" columnWidth="555" leftMargin="20" rightMargin="20" topMargin="20" bottomMargin="20" uuid="2e9583be-f081-46a8-ab4f-06825850ee37">
<property name="com.jaspersoft.studio.data.defaultdataadapter" value="One Empty Record"/>
<style name="Table_TH" mode="Opaque" backcolor="#F0F8FF">
<box>
<pen lineWidth="0.5" lineColor="#000000"/>
<topPen lineWidth="0.5" lineColor="#000000"/>
<leftPen lineWidth="0.5" lineColor="#000000"/>
<bottomPen lineWidth="0.5" lineColor="#000000"/>
<rightPen lineWidth="0.5" lineColor="#000000"/>
</box>
</style>
<style name="Table_CH" mode="Opaque" backcolor="#BFE1FF">
<box>
<pen lineWidth="0.5" lineColor="#000000"/>
<topPen lineWidth="0.5" lineColor="#000000"/>
<leftPen lineWidth="0.5" lineColor="#000000"/>
<bottomPen lineWidth="0.5" lineColor="#000000"/>
<rightPen lineWidth="0.5" lineColor="#000000"/>
</box>
</style>
<style name="Table_TD" mode="Opaque" backcolor="#FFFFFF">
<box>
<pen lineWidth="0.5" lineColor="#000000"/>
<topPen lineWidth="0.5" lineColor="#000000"/>
<leftPen lineWidth="0.5" lineColor="#000000"/>
<bottomPen lineWidth="0.5" lineColor="#000000"/>
<rightPen lineWidth="0.5" lineColor="#000000"/>
</box>
</style>
<style name="Table 1_TH" mode="Opaque" backcolor="#F0F8FF">
<box>
<pen lineWidth="0.5" lineColor="#000000"/>
<topPen lineWidth="0.5" lineColor="#000000"/>
<leftPen lineWidth="0.5" lineColor="#000000"/>
<bottomPen lineWidth="0.5" lineColor="#000000"/>
<rightPen lineWidth="0.5" lineColor="#000000"/>
</box>
</style>
<style name="Table 1_CH" mode="Opaque" backcolor="#BFE1FF">
<box>
<pen lineWidth="0.5" lineColor="#000000"/>
<topPen lineWidth="0.5" lineColor="#000000"/>
<leftPen lineWidth="0.5" lineColor="#000000"/>
<bottomPen lineWidth="0.5" lineColor="#000000"/>
<rightPen lineWidth="0.5" lineColor="#000000"/>
</box>
</style>
<style name="Table 1_TD" mode="Opaque" backcolor="#FFFFFF">
<box>
<pen lineWidth="0.5" lineColor="#000000"/>
<topPen lineWidth="0.5" lineColor="#000000"/>
<leftPen lineWidth="0.5" lineColor="#000000"/>
<bottomPen lineWidth="0.5" lineColor="#000000"/>
<rightPen lineWidth="0.5" lineColor="#000000"/>
</box>
</style>
<subDataset name="Dataset1" uuid="de015a45-b31b-4e76-b602-c48d2099b2f0">
<parameter name="medicineName" class="java.lang.String"/>
<parameter name="schedule" class="java.lang.String"/>
<parameter name="date" class="java.lang.String"/>
<parameter name="hour" class="java.lang.String"/>
<parameter name="dosage" class="java.lang.String"/>
<parameter name="Taken" class="java.lang.String"/>
<queryString>
<![CDATA[]]>
</queryString>
<field name="date" class="java.lang.String"/>
<field name="medicineName" class="java.lang.String"/>
<field name="dosage" class="java.lang.String"/>
<field name="hour" class="java.lang.String"/>
<field name="taken" class="java.lang.String"/>
<field name="schedule" class="java.lang.String"/>
</subDataset>
<parameter name="disease" class="java.lang.String"/>
<parameter name="doctor" class="java.lang.String"/>
<parameter name="pharmacy" class="java.lang.String"/>
<parameter name="symptom" class="java.lang.String"/>
<parameter name="profileName" class="java.lang.String">
<parameterDescription><![CDATA[]]></parameterDescription>
</parameter>
<parameter name="age" class="java.lang.String"/>
<parameter name="gender" class="java.lang.String"/>
<parameter name="bloodGroup" class="java.lang.String"/>
<queryString>
<![CDATA[]]>
</queryString>
<background>
<band splitType="Stretch"/>
</background>
<pageHeader>
<band height="101">
<textField>
<reportElement x="0" y="1" width="180" height="20" uuid="38b835c7-7f37-4208-9e17-f1265afe7abd"/>
<textElement>
<font fontName="Times New Roman" size="16" isBold="true"/>
</textElement>
<textFieldExpression><![CDATA[$P{profileName}]]></textFieldExpression>
</textField>
<staticText>
<reportElement x="0" y="35" width="30" height="20" uuid="9c9ddeee-18b9-4d0c-aad9-32e8e00d375a"/>
<textElement>
<font fontName="Times New Roman" size="14" isBold="true"/>
</textElement>
<text><![CDATA[Age]]></text>
</staticText>
<textField>
<reportElement x="30" y="36" width="17" height="19" uuid="35a16a58-bef5-4753-a3a6-5478eeda8aac"/>
<textElement>
<font fontName="Times New Roman" size="14" isBold="true"/>
</textElement>
<textFieldExpression><![CDATA[$P{age}]]></textFieldExpression>
</textField>
<line>
<reportElement x="51" y="35" width="1" height="20" uuid="7962e3e8-0f3d-4096-8145-569d5044f401">
<property name="com.jaspersoft.studio.unit.x" value="pixel"/>
<property name="com.jaspersoft.studio.unit.y" value="pixel"/>
<property name="com.jaspersoft.studio.unit.width" value="pixel"/>
</reportElement>
</line>
<staticText>
<reportElement x="55" y="35" width="50" height="20" uuid="2d568652-4551-40b8-9a0f-b504cced79d5"/>
<textElement>
<font fontName="Times New Roman" size="14" isBold="true"/>
</textElement>
<text><![CDATA[Gender]]></text>
</staticText>
<textField>
<reportElement x="102" y="35" width="46" height="20" uuid="1755ba6d-a486-4adf-83da-1a06af7c1369"/>
<textElement verticalAlignment="Middle">
<font fontName="Times New Roman" size="14" isBold="true"/>
</textElement>
<textFieldExpression><![CDATA[$P{gender}]]></textFieldExpression>
</textField>
<line>
<reportElement x="150" y="35" width="1" height="20" uuid="6371ec0f-d26f-4e82-88ec-26a724c40d54">
<property name="com.jaspersoft.studio.unit.x" value="pixel"/>
<property name="com.jaspersoft.studio.unit.y" value="pixel"/>
<property name="com.jaspersoft.studio.unit.width" value="pixel"/>
</reportElement>
</line>
<staticText>
<reportElement x="150" y="36" width="80" height="20" uuid="5634ce23-b218-4ffe-8237-cc49ceeea862"/>
<textElement>
<font fontName="Times New Roman" size="14" isBold="true"/>
</textElement>
<text><![CDATA[Blood Group]]></text>
</staticText>
<textField>
<reportElement x="230" y="36" width="51" height="21" uuid="45df73f2-4a33-47e9-8d0b-804c99946bcc"/>
<textElement>
<font fontName="Times New Roman" size="14" isBold="true"/>
</textElement>
<textFieldExpression><![CDATA[$P{bloodGroup}]]></textFieldExpression>
</textField>
<staticText>
<reportElement x="-5" y="57" width="63" height="20" uuid="ea748f7d-f4d0-4e9e-8379-a52e74b0cbf2"/>
<textElement textAlignment="Center" verticalAlignment="Middle">
<font fontName="Times New Roman" size="12" isBold="true"/>
</textElement>
<text><![CDATA[Condition]]></text>
</staticText>
<textField>
<reportElement x="52" y="57" width="90" height="20" forecolor="#F51511" uuid="ae53e0e0-d755-4cfd-9e7a-b3bbde881f9d"/>
<box>
<topPen lineColor="#F22824"/>
<leftPen lineColor="#F22824"/>
<bottomPen lineColor="#F22824"/>
<rightPen lineColor="#F22824"/>
</box>
<textElement textAlignment="Center" verticalAlignment="Middle" markup="none">
<font size="12" isBold="true"/>
</textElement>
<textFieldExpression><![CDATA[$P{disease}]]></textFieldExpression>
</textField>
<line>
<reportElement x="140" y="55" width="1" height="20" uuid="1f89c71f-d8a3-4dee-9943-417470344334">
<property name="com.jaspersoft.studio.unit.x" value="pixel"/>
<property name="com.jaspersoft.studio.unit.y" value="pixel"/>
<property name="com.jaspersoft.studio.unit.width" value="pixel"/>
</reportElement>
</line>
<staticText>
<reportElement x="142" y="57" width="63" height="20" uuid="e887596a-a3b6-4285-afca-4d96b9c27f64"/>
<textElement textAlignment="Center" verticalAlignment="Middle">
<font fontName="Times New Roman" size="12" isBold="true"/>
</textElement>
<text><![CDATA[Symptoms]]></text>
</staticText>
<textField>
<reportElement x="200" y="57" width="100" height="20" forecolor="#F21511" uuid="3ba4e883-6b4e-44a8-8360-b1acff38e3d9"/>
<textElement textAlignment="Center" verticalAlignment="Middle">
<font fontName="Times New Roman" size="12" isBold="true"/>
</textElement>
<textFieldExpression><![CDATA[$P{symptom}]]></textFieldExpression>
</textField>
<line>
<reportElement x="300" y="57" width="1" height="20" uuid="3a76da0b-a958-4dee-bb9a-560098b496d6">
<property name="com.jaspersoft.studio.unit.x" value="pixel"/>
<property name="com.jaspersoft.studio.unit.y" value="pixel"/>
<property name="com.jaspersoft.studio.unit.width" value="pixel"/>
</reportElement>
</line>
<staticText>
<reportElement x="301" y="57" width="63" height="20" uuid="5fcd5ba3-a11a-45e3-9e22-56b272211390"/>
<textElement textAlignment="Center" verticalAlignment="Middle">
<font fontName="Times New Roman" size="12" isBold="true"/>
</textElement>
<text><![CDATA[Doctors]]></text>
</staticText>
<textField>
<reportElement x="360" y="57" width="100" height="21" forecolor="#FA1D19" uuid="a9f3ff9e-74b8-4112-b1c1-cdca8bd918b3"/>
<textElement textAlignment="Center" verticalAlignment="Middle">
<font fontName="Times New Roman" size="12" isBold="true"/>
</textElement>
<textFieldExpression><![CDATA[$P{doctor}]]></textFieldExpression>
</textField>
<line>
<reportElement x="-3" y="85" width="560" height="1" uuid="489b1135-0cd0-4d47-8ed4-6a689582c264">
<property name="com.jaspersoft.studio.unit.x" value="pixel"/>
<property name="com.jaspersoft.studio.unit.y" value="pixel"/>
<property name="com.jaspersoft.studio.unit.width" value="pixel"/>
<property name="com.jaspersoft.studio.unit.height" value="pixel"/>
</reportElement>
</line>
<line>
<reportElement x="0" y="90" width="281" height="1" uuid="f16072f4-ed14-410c-a6fd-2851b2f88f04">
<property name="com.jaspersoft.studio.unit.x" value="pixel"/>
<property name="com.jaspersoft.studio.unit.y" value="pixel"/>
<property name="com.jaspersoft.studio.unit.width" value="pixel"/>
<property name="com.jaspersoft.studio.unit.height" value="pixel"/>
</reportElement>
</line>
<line>
<reportElement x="0" y="31" width="560" height="1" uuid="d515cf7a-05b5-4a5e-b30c-95b8e79f2381">
<property name="com.jaspersoft.studio.unit.x" value="pixel"/>
<property name="com.jaspersoft.studio.unit.y" value="pixel"/>
<property name="com.jaspersoft.studio.unit.width" value="pixel"/>
<property name="com.jaspersoft.studio.unit.height" value="pixel"/>
</reportElement>
</line>
</band>
</pageHeader>
<detail>
<band height="50" splitType="Stretch">
<componentElement>
<reportElement x="0" y="0" width="100" height="30" uuid="33832d43-6539-48db-ae31-fc5836c7f038">
<property name="com.jaspersoft.studio.layout" value="com.jaspersoft.studio.editor.layout.HorizontalRowLayout"/>
</reportElement>
<jr:list xmlns:jr="http://jasperreports.sourceforge.net/jasperreports/components" xsi:schemaLocation="http://jasperreports.sourceforge.net/jasperreports/components http://jasperreports.sourceforge.net/xsd/components.xsd">
<datasetRun subDataset="Dataset1" uuid="b8e46627-a532-4836-bcb1-56f47d997ef9">
<dataSourceExpression><![CDATA[new net.sf.jasperreports.engine.JREmptyDataSource() ]]></dataSourceExpression>
</datasetRun>
<jr:listContents height="30" width="100">
<textField>
<reportElement x="0" y="0" width="20" height="30" uuid="7985e712-7deb-4f22-869f-2f2ebcd77f59"/>
<textFieldExpression><![CDATA[$F{date}]]></textFieldExpression>
</textField>
<textField>
<reportElement x="20" y="0" width="16" height="30" uuid="0b0ede12-bd96-46ba-afd8-41581438b6a4"/>
<textFieldExpression><![CDATA[$F{medicineName}]]></textFieldExpression>
</textField>
<textField>
<reportElement x="36" y="0" width="16" height="30" uuid="5c597083-edf0-4159-b455-018f9b83f8ee"/>
<textFieldExpression><![CDATA[$F{dosage}]]></textFieldExpression>
</textField>
<textField>
<reportElement x="52" y="0" width="16" height="30" uuid="483a1dc0-d6a5-40e6-8e51-ca03cde8a7b1"/>
<textFieldExpression><![CDATA[$F{hour}]]></textFieldExpression>
</textField>
<textField>
<reportElement x="68" y="0" width="16" height="30" uuid="2bdf851b-2981-40a2-b3fd-42bd8df3b990"/>
<textFieldExpression><![CDATA[$F{taken}]]></textFieldExpression>
</textField>
<textField>
<reportElement x="84" y="0" width="16" height="30" uuid="cf0cf0e7-ec90-42d4-ba3f-fb27563890fe"/>
<textFieldExpression><![CDATA[$F{schedule}]]></textFieldExpression>
</textField>
</jr:listContents>
</jr:list>
</componentElement>
</band>
</detail>
</jasperReport>
最佳答案
这是因为您在将 JRBeanCollectionDataSource
传递到主报表时为列表组件使用了子数据集。因此,主报告具有 JRBeanCollectionDataSource
,但您的列表组件具有 JREmptyDataSource
解决方案
将列表作为参数传递
parameter.put("medicineList",new MedicineDAO().getMedicineList(id));
通过 JREmptyDataSource到报告(您不使用此数据源,请传递 1 条记录以显示详细信息区域一次)
JasperPrint jasperPrint = JasperFillManager.fillReport(jasperReport,
parameters, new JREmptyDataSource(1))
将新参数添加到 jrxml 并将正确的数据源传递到 jr:list
<parameter name="medicineList" class="java.util.List" isForPrompting="false"/>
....
<jr:list xmlns:jr="http://jasperreports.sourceforge.net/jasperreports/components" xsi:schemaLocation="http://jasperreports.sourceforge.net/jasperreports/components http://jasperreports.sourceforge.net/xsd/components.xsd">
<datasetRun subDataset="Dataset1" uuid="b8e46627-a532-4836-bcb1-56f47d997ef9">
<dataSourceExpression><![CDATA[new net.sf.jasperreports.engine.data.JRBeanCollectionDataSource($P{medicineList}) ]]></dataSourceExpression>
</datasetRun>
....
此外,您对参数也有同样的困惑,主报告中使用的参数(不在列表组件内部)需要在主报告级别(不在子数据集内部)定义,组件中使用的参数定义是正确的它们位于子数据集中,但您还需要将它们传递给组件。
关于java - 为什么 JRBeanCollectionDataSource 使用 jr :list component? 给出传递 List 的空字段,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/36744136/
Github:https://github.com/jjvang/PassIntentDemo 我一直在关注有关按 Intent 传递对象的教程:https://www.javacodegeeks.c
我有一个 View ,其中包含自动生成的 text 类型的 input 框。当我单击“通过电子邮件发送结果”按钮时,代码会将您带到 CalculatedResults Controller 中的 Em
我有一个基本的docker镜像,我将以此为基础构建自己的镜像。我没有基础镜像的Dockerfile。 基本上,基本镜像使用两个--env arg,一个接受其许可证,一个选择在容器中激活哪个框架。我可以
假设我想计算 2^n 的总和,n 范围从 0 到 100。我可以编写以下内容: seq { 0 .. 100 } |> Seq.sumBy ((**) 2I) 但是,这与 (*) 或其他运算符/函数不
我有这个网址: http://www.example.com/get_url.php?ID=100&Link=http://www.test.com/page.php?l=1&m=7 当我打印 $_G
我想将 window.URL.createObjectURL(file) 创建的地址传递给 dancer.js 但我得到 GET blob:http%3A//localhost/b847c5cd-aa
我想知道如何将 typedef 传递给函数。例如: typedef int box[3][3]; box empty, *board[3][3]; 我如何将 board 传递给函数?我
我正在将一些代码从我的 Controller 移动到核心数据应用程序中的模型。 我编写了一个方法,该方法为我定期发出的特定获取请求返回 NSManagedObjectID。 + (NSManagedO
为什么我不能将类型化数组传递到采用 any[] 的函数/构造函数中? typedArray = new MyType[ ... ]; items = new ko.observableArray(ty
我是一名新的 Web 开发人员,正在学习 html5 和 javascript。 我有一个带有“选项卡”的网页,可以使网页的某些部分消失并重新出现。 链接如下: HOME 和 JavaScript 函
我试图将对函数的引用作为参数传递 很难解释 我会写一些伪代码示例 (calling function) function(hello()); function(pass) { if this =
我在尝试调用我正在创建的 C# 项目中的函数时遇到以下错误: System.Runtime.InteropServices.COMException: Operation is not allowed
使用 ksh。尝试重用当前脚本而不修改它,基本上可以归结为如下内容: `expr 5 $1 $2` 如何将乘法命令 (*) 作为参数 $1 传递? 我首先尝试使用“*”,甚至是\*,但没有用。我尝试
我一直在研究“Play for Java”这本书,这本书非常棒。我对 Java 还是很陌生,但我一直在关注这些示例,我有点卡在第 3 章上了。可以在此处找到代码:Play for Java on Gi
我知道 Javascript 中的对象是通过引用复制/传递的。但是函数呢? 当我跳到一些令人困惑的地方时,我正在尝试这段代码。这是代码片段: x = function() { console.log(
我希望能够像这样传递参数: fn(a>=b) or fn(a!=b) 我在 DjangoORM 和 SQLAlchemy 中看到了这种行为,但我不知道如何实现它。 最佳答案 ORM 使用 specia
在我的 Angular 项目中,我最近将 rxjs 升级到版本 6。现在,来自 npm 的模块(在 node_modules 文件夹内)由于一些破坏性更改而失败(旧的进口不再有效)。我为我的代码调整了
这个问题在这里已经有了答案: The issue of * in Command line argument (6 个答案) 关闭 3 年前。 我正在编写一个关于反向波兰表示法的 C 程序,它通过命
$(document).ready(function() { function GetDeals() { alert($(this).attr("id")); } $('.filter
下面是一个例子: 复制代码 代码如下: use strict; #这里是两个数组 my @i =('1','2','3'); my @j =('a','b','c'); &n
我是一名优秀的程序员,十分优秀!