我尝试了几个参数显示选项:
alert_type.name --> varchar
alert_type.id --> integer
Alert_Type --> java.util.collection
1.报表查询中的参数:$X{IN, alert_type.name, Alert_Type}
1.b 报表中的参数显示:[Alert1, Alert2, ..., Alertn)
在这种情况下,选择的参数显示正确,但我需要将 alert_type.name (varchar) 更改为 alert_type.id (integer)
2.报表查询中的参数:$X{IN, alert_type.id, Alert_Type}
2.b 报表中的参数显示:没有生成报表所以我尝试了3号。
3.a 报表查询:$X{IN, COALESCE (CAST (alert_type.id AS varchar (100))), Alert_Type}
3.b 报表中的参数显示:[1,2,3,4....n]
现在的问题是如何在参数中显示 Alert1、Alert2... 而不是 1,2...?所以不想看到 ID 而是看到名称。
以下是请求的相关代码:
<?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="Alert Report" language="groovy" pageWidth="842" pageHeight="595" orientation="Landscape" whenNoDataType="AllSectionsNoDetail" columnWidth="802" leftMargin="20" rightMargin="20" topMargin="20" bottomMargin="20" uuid="94b79d03-4940-4b89-bbf7-552871a5f749">
<property name="ireport.zoom" value="1.0"/>
<property name="ireport.x" value="0"/>
<property name="ireport.y" value="0"/>
<property name="ireport.jasperserver.reportUnit" value="/reports/LTA/Alert_Report_2"/>
<property name="ireport.jasperserver.url" value="http://10.5.5.59:8080/jasperserver/services/repository"/>
<style name="table">
<box>
<pen lineWidth="1.0" lineColor="#000000"/>
</box>
</style>
<style name="table_TH" mode="Opaque" backcolor="#73B0E6">
<box>
<topPen lineWidth="0.5" lineColor="#000000"/>
<bottomPen lineWidth="0.5" lineColor="#000000"/>
</box>
</style>
<style name="table_CH" mode="Opaque" backcolor="#CFDBE6">
<box>
<topPen lineWidth="0.5" lineColor="#000000"/>
<bottomPen lineWidth="0.5" lineColor="#000000"/>
</box>
</style>
<style name="table_TD" mode="Opaque" backcolor="#FFFFFF">
<box>
<topPen lineWidth="0.5" lineColor="#000000"/>
<bottomPen lineWidth="0.5" lineColor="#000000"/>
</box>
</style>
<style name="table 1">
<box>
<pen lineWidth="1.0" lineColor="#000000"/>
</box>
</style>
<style name="table 1_TH" mode="Opaque" backcolor="#73B0E6">
<box>
<topPen lineWidth="0.5" lineColor="#000000"/>
<bottomPen lineWidth="0.5" lineColor="#000000"/>
</box>
</style>
<style name="table 1_CH" mode="Opaque" backcolor="#CFDBE6">
<box>
<topPen lineWidth="0.5" lineColor="#000000"/>
<bottomPen lineWidth="0.5" lineColor="#000000"/>
</box>
</style>
<style name="table 1_TD" mode="Opaque" backcolor="#FFFFFF">
<box>
<topPen lineWidth="0.5" lineColor="#000000"/>
<bottomPen lineWidth="0.5" lineColor="#000000"/>
</box>
</style>
<style name="table 2">
<box>
<pen lineWidth="1.0" lineColor="#000000"/>
</box>
</style>
<style name="table 2_TH" mode="Opaque" backcolor="#73B0E6">
<box>
<topPen lineWidth="0.5" lineColor="#000000"/>
<bottomPen lineWidth="0.5" lineColor="#000000"/>
</box>
</style>
<style name="table 2_CH" mode="Opaque" backcolor="#CFDBE6">
<box>
<topPen lineWidth="0.5" lineColor="#000000"/>
<bottomPen lineWidth="0.5" lineColor="#000000"/>
</box>
</style>
<style name="table 2_TD" mode="Opaque" backcolor="#FFFFFF">
<box>
<topPen lineWidth="0.5" lineColor="#000000"/>
<bottomPen lineWidth="0.5" lineColor="#000000"/>
</box>
</style>
<style name="table 3">
<box>
<pen lineWidth="1.0" lineColor="#000000"/>
</box>
</style>
<style name="table 3_TH" mode="Opaque" backcolor="#F0F8FF">
<box>
<topPen lineWidth="0.5" lineColor="#000000"/>
<bottomPen lineWidth="0.5" lineColor="#000000"/>
</box>
</style>
<style name="table 3_CH" mode="Opaque" backcolor="#BFE1FF">
<box>
<topPen lineWidth="0.5" lineColor="#000000"/>
<bottomPen lineWidth="0.5" lineColor="#000000"/>
</box>
</style>
<style name="table 3_TD" mode="Opaque" backcolor="#FFFFFF">
<box>
<topPen lineWidth="0.5" lineColor="#000000"/>
<bottomPen lineWidth="0.5" lineColor="#000000"/>
</box>
</style>
<subDataset name="New Dataset 1" uuid="acd41491-54fa-4316-8fe7-de309d164657">
<parameter name="Alert_Type" class="java.util.Collection"/>
<queryString>
<![CDATA[SELECT
alert.event_timestamp,
alert_type.id,
alert_type.name
FROM
alert
JOIN
alert_type ON alert.type = alert_type.id
WHERE
$X{IN, COALESCE (CAST (alert_type.id AS varchar (100))), Alert_Type}]]>
</queryString>
<field name="event_timestamp" class="java.sql.Timestamp"/>
<field name="id" class="java.lang.Integer"/>
<field name="name" class="java.lang.String"/>
</subDataset>
<parameter name="Alert_Type" class="java.util.Collection"/>
<queryString>
<![CDATA[SELECT
alert.event_timestamp,
alert_type.id,
alert_type.name
FROM
alert
JOIN
alert_type ON alert.type = alert_type.id
WHERE
$X{IN, COALESCE (CAST (alert_type.id AS varchar (100))), Alert_Type}]]>
</queryString>
<field name="event_timestamp" class="java.sql.Timestamp"/>
<field name="id" class="java.lang.Integer"/>
<field name="name" class="java.lang.String"/>
<background>
<band splitType="Stretch"/>
</background>
<title>
<band height="84" splitType="Stretch">
<staticText>
<reportElement uuid="673a92ae-a498-47f7-8bb2-cf09f3e08b50" x="0" y="0" width="154" height="30"/>
<textElement>
<font fontName="Myriad Pro" size="24"/>
</textElement>
<text><![CDATA[Alert Report]]></text>
</staticText>
<staticText>
<reportElement uuid="b6c26413-0c0d-40d3-81f7-33b8f15799d8" x="599" y="33" width="83" height="20"/>
<textElement textAlignment="Right" verticalAlignment="Middle">
<font fontName="Myriad Pro"/>
</textElement>
<text><![CDATA[Creation Time: ]]></text>
</staticText>
<textField pattern="dd/MM/yyyy HH:mm:ss">
<reportElement uuid="f5b19632-5fda-44bb-85d3-963aff9e744f" x="682" y="33" width="120" height="20"/>
<textElement textAlignment="Left" verticalAlignment="Middle">
<font fontName="Myriad Pro"/>
</textElement>
<textFieldExpression><![CDATA[new java.util.Date()]]></textFieldExpression>
</textField>
<line>
<reportElement uuid="0d130948-71cd-490d-93cf-6f43c6ae924b" x="0" y="30" width="802" height="1"/>
</line>
<textField isStretchWithOverflow="true" pattern="">
<reportElement uuid="1c06e35e-23a6-4fd4-90a8-c88116876423" positionType="Float" stretchType="RelativeToBandHeight" x="116" y="55" width="673" height="20" isPrintWhenDetailOverflows="true"/>
<textElement verticalAlignment="Middle">
<font fontName="Myriad Pro"/>
</textElement>
<textFieldExpression><![CDATA[$P{Alert_Type}]]></textFieldExpression>
</textField>
<staticText>
<reportElement uuid="e6d2f050-af99-4a2b-ba4a-1491365ffb53" x="0" y="55" width="109" height="20"/>
<textElement textAlignment="Center" verticalAlignment="Middle">
<font fontName="Myriad Pro" size="10"/>
</textElement>
<text><![CDATA[Selected Alert Types: ]]></text>
</staticText>
</band>
</title>
<detail>
<band height="177" splitType="Stretch">
<printWhenExpression><![CDATA[$V{REPORT_COUNT}==1]]></printWhenExpression>
<componentElement>
<reportElement uuid="277271e9-b212-446c-9be3-84bd266ce97b" key="table 3" style="table 3" x="0" y="14" width="360" height="50"/>
<jr:table 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="New Dataset 1" uuid="e7fe0328-3db3-42ab-aa27-8c9ad0843710">
<connectionExpression><![CDATA[$P{REPORT_CONNECTION}]]></connectionExpression>
</datasetRun>
<jr:column width="90" uuid="21dcad58-1a5c-4d93-9c59-8346e4923544">
<jr:columnHeader style="table 3_CH" height="30">
<staticText>
<reportElement uuid="4e38f6d5-e810-440d-b66e-d10284cb8cc3" x="0" y="0" width="90" height="30"/>
<textElement/>
<text><![CDATA[event_timestamp]]></text>
</staticText>
</jr:columnHeader>
<jr:detailCell style="table 3_TD" height="20">
<textField>
<reportElement uuid="ffdaada2-ec5e-413f-9c67-0eba447e4581" x="0" y="0" width="90" height="20"/>
<textElement/>
<textFieldExpression><![CDATA[$F{event_timestamp}]]></textFieldExpression>
</textField>
</jr:detailCell>
</jr:column>
<jr:column width="90" uuid="dccb3cdd-5cb1-413f-9d00-24fc950a35af">
<jr:columnHeader style="table 3_CH" height="30">
<staticText>
<reportElement uuid="394a428e-351d-4271-bc04-f58018ea0077" x="0" y="0" width="90" height="30"/>
<textElement/>
<text><![CDATA[id]]></text>
</staticText>
</jr:columnHeader>
<jr:detailCell style="table 3_TD" height="20">
<textField>
<reportElement uuid="311b77d8-3d60-4149-8dd9-52ee5b3062c8" x="0" y="0" width="90" height="20"/>
<textElement/>
<textFieldExpression><![CDATA[$F{id}]]></textFieldExpression>
</textField>
</jr:detailCell>
</jr:column>
<jr:column width="90" uuid="bb72b714-6cac-45a1-a5db-c5d8ebc17b02">
<jr:columnHeader style="table 3_CH" height="30">
<staticText>
<reportElement uuid="d0d4e3d7-fedf-4fc7-837e-97572d0c1a56" x="0" y="0" width="90" height="30"/>
<textElement/>
<text><![CDATA[name]]></text>
</staticText>
</jr:columnHeader>
<jr:detailCell style="table 3_TD" height="20">
<textField>
<reportElement uuid="18bc66b3-228f-4d32-a764-95a72950e430" x="0" y="0" width="90" height="20"/>
<textElement/>
<textFieldExpression><![CDATA[$F{name}]]></textFieldExpression>
</textField>
</jr:detailCell>
</jr:column>
</jr:table>
</componentElement>
</band>
</detail>
<pageFooter>
<band height="28" splitType="Stretch">
<textField>
<reportElement uuid="7dc7143d-623f-46ef-baf0-0297979eea1c" x="682" y="5" width="80" height="20"/>
<textElement textAlignment="Right">
<font fontName="Myriad Pro"/>
</textElement>
<textFieldExpression><![CDATA["Page "+$V{PAGE_NUMBER}+" of"]]></textFieldExpression>
</textField>
<textField evaluationTime="Report">
<reportElement uuid="6c6ad707-c542-42d7-88b7-ef4a4ba4d473" x="762" y="5" width="40" height="20"/>
<textElement>
<font fontName="Myriad Pro"/>
</textElement>
<textFieldExpression><![CDATA[" " + $V{PAGE_NUMBER}]]></textFieldExpression>
</textField>
</band>
</pageFooter>
</jasperReport>