我从我的参数中输入了名称kem的输入列表。它是kem 1
,kem 2
,kem 3
。我创建 $x{in,pd_id,Kem}
作为参数,但结果只显示来自三个kem的kem 1
。我想要的是当我列出kem的列表名称时,数据将显示所有数据。那是kem 1
,kem 2
,kem 3
。
这是我的代码:
<?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="testspace" language="javascript" pageWidth="595" pageHeight="842" columnWidth="555" leftMargin="20" rightMargin="20" topMargin="20" bottomMargin="20">
<parameter name="kem" class="java.util.Collection">
<defaultValueExpression><![CDATA[]]></defaultValueExpression>
</parameter>
<queryString>
<![CDATA[select
PD_ID,
PD_NAME
from wf_proc_def where $X{IN,PD_ID,kem}]]>
</queryString>
<field name="PD_ID" class="java.math.BigDecimal"/>
<field name="PD_NAME" class="java.lang.String"/>
<background>
<band splitType="Stretch"/>
</background>
<title>
<band height="79" splitType="Stretch">
<textField isBlankWhenNull="true">
<reportElement x="118" y="24" width="334" height="20"/>
<textElement/>
<textFieldExpression><![CDATA[ ("1".equals($P{kem})) ? "kem1"
:("2".equals($P{kem})) ? "kem2"
:("3".equals($P{kem})) ? "kem3"
:("4".equals($P{kem})) ? "kem4"
:("5".equals($P{kem})) ? "kem5"
:null]]></textFieldExpression>
</textField>
</band>
</title>
</jasperReport>
答案 0 :(得分:2)
我认为您的参数kem
有问题,必须包含值列表。您应该初始化此参数。
这是工作样本(适用于iReport的示例数据库):
<?xml version="1.0" encoding="UTF-8"?>
<jasperReport ..>
<parameter name="cities" class="java.util.List">
<defaultValueExpression><![CDATA[Arrays.asList(new String[] {"Dallas", "Lyon", "Paris"})]]></defaultValueExpression>
</parameter>
<queryString>
<![CDATA[SELECT ID, CITY FROM ADDRESS WHERE $X{IN,CITY,cities}]]>
</queryString>
<field name="ID" class="java.lang.Integer"/>
<field name="CITY" class="java.lang.String"/>
<title>
<band height="79" splitType="Stretch">
<textField>
<reportElement x="0" y="12" width="100" height="20"/>
<textElement/>
<textFieldExpression><![CDATA[$P{cities}]]></textFieldExpression>
</textField>
</band>
</title>
<detail>
<band height="20" splitType="Stretch">
<textField>
<reportElement x="0" y="0" width="100" height="20"/>
<textElement/>
<textFieldExpression><![CDATA[$F{CITY}]]></textFieldExpression>
</textField>
<textField>
<reportElement x="100" y="0" width="100" height="20"/>
<textElement/>
<textFieldExpression><![CDATA[$F{ID}]]></textFieldExpression>
</textField>
</band>
</detail>
</jasperReport>
iReport
预览功能中生成的结果:
<强> 更新 强>:
如何借助google guava库
按键解析值样本:
<?xml version="1.0" encoding="UTF-8"?>
<jasperReport ..>
<import value="com.google.common.collect.*"/>
<import value="com.google.common.base.*"/>
<parameter name="cities" class="java.util.List">
<defaultValueExpression><![CDATA[Arrays.asList(new String[] {"1", "2", "3"})]]></defaultValueExpression>
</parameter>
<parameter name="citiesMap" class="java.util.Map">
<defaultValueExpression><![CDATA[new ImmutableMap.Builder<String, String>().put("1", "Dallas").put("2", "Lyon").put("3", "Paris").build()]]></defaultValueExpression>
</parameter>
...
<title>
<band height="79" splitType="Stretch">
<textField>
<reportElement x="0" y="12" width="100" height="20"/>
<textElement/>
<textFieldExpression><![CDATA[$P{cities}]]></textFieldExpression>
</textField>
<textField>
<reportElement x="185" y="12" width="100" height="20"/>
<textElement/>
<textFieldExpression><![CDATA[Maps.filterKeys($P{citiesMap}, Predicates.in($P{cities})).values()]]></textFieldExpression>
</textField>
</band>
</title>
...
</jasperReport>
结果将是: