Jasper 软报告表达式从对象数组参数中获取逗号分隔的字符串

问题描述 投票:0回答:1

我正在尝试从传递到 jaspersoft 报告中的参数中获取逗号分隔的字符串。这是我尝试过的,但 jasper studio 说该表达式无效。请帮忙。

IntStream.range(0, $P{cities}.size()).mapToObj(index -> $P{cities}.get(index).get("label")).collect(Collectors.joining(", "))
java jasper-reports jaspersoft-studio
1个回答
0
投票

我修改了一个用变量制作的小例子,它应该与参数一起工作:

<?xml version="1.0" encoding="UTF-8"?>
<!-- Created with Jaspersoft Studio version 6.21.0.final using JasperReports Library version 6.21.0-4f56c4f36cd19e17675219a9ac4692d5f0f13b06  -->
<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="Führungskräftegespräch" pageWidth="602" pageHeight="3000" columnWidth="602" leftMargin="0" rightMargin="0" topMargin="0" bottomMargin="0" isFloatColumnFooter="true" uuid="80afabe3-2d3d-4c26-8c41-8e3b10a62a77">
    <property name="com.jaspersoft.studio.data.defaultdataadapter" value="One Empty Record"/>
    <queryString>
        <![CDATA[]]>
    </queryString>
    <variable name="cities" class="java.util.List">
        <variableExpression><![CDATA[java.util.stream.LongStream.range(0,3).mapToObj(i -> java.util.Collections.singletonMap("label", String.valueOf(i))).collect(java.util.stream.Collectors.toList())]]></variableExpression>
    </variable>
    <background>
        <band splitType="Stretch"/>
    </background>
    <summary>
        <band height="842">
            <property name="com.jaspersoft.studio.unit.height" value="px"/>
            <staticText>
                <reportElement x="210" y="10" width="100" height="30" uuid="0ac46265-4524-42a2-a14a-220ee44b165d"/>
                <text><![CDATA[Main Report]]></text>
            </staticText>
            <textField>
                <reportElement x="60" y="120" width="371" height="81" uuid="02bbcdb4-3ad4-4043-b257-11ec5c378e15"/>
                <textFieldExpression><![CDATA[$V{cities}.stream().map(o -> ((Map<String,Object>)o).get("label").toString()).collect(java.util.stream.Collectors.joining(","))]]></textFieldExpression>
            </textField>
        </band>
    </summary>
</jasperReport>
© www.soinside.com 2019 - 2024. All rights reserved.