如何在JasperReports中使用另一个变量的值增加变量?

sve*_*hie 17 jasper-reports

我需要在subReport中计算我正在计算的项目的总数.为此,我认为我需要将该变量的值添加到每个迭代的另一个变量中,或者用该值"递增"它.为每个组调用subReport,我得到该组的总数.我需要添加变量值,而不是数据库列/字段.

我收到一个整数returnValuesubReport,这本身就是在子报告的行数.我希望获得总计,因为subReport从我的主SQL查询中为不同的结果(每个为GROUP)调用多次.我想把所有的结果加起来,但我得到了一个null价值.我尝试添加一个操作subReport作为一个新的returnValue并选择Sum作为操作,但这也产生了一个null.


   <variable name="itemCount" class="java.lang.Integer" resetType="None"/>
   <variable name="grandCount" 
      class="java.lang.Integer" 
      incrementType="Group" 
      incrementGroup="ITEM_BUNDLE">
      <variableExpression><![CDATA[$V{itemCount}]]></variableExpression>
   </variable>

... <returnValue subreportVariable="countItems" toVariable="itemCount"/>

cet*_*nar 7

添加属性calculation="Sum"variable name="grandCount"

或传递grandCount给子报告作为参数

<subreportParameter name="grandCount">
<subreportParameterExpression><![CDATA[$P{grandCount}]]></subreportParameterExpression>
</subreportParameter>
Run Code Online (Sandbox Code Playgroud)

在子报表中使用参数grantCount的 initialValue 声明变量countItems

<variable name="countItems" .... >
   <variableExpression><![CDATA[$P{itemCount} + $P{grandCount}]]></variableExpression>
   <initialValueExpression><![CDATA[$P{grandCount}]]></initialValueExpression>
</variable>
Run Code Online (Sandbox Code Playgroud)

并返回

<returnValue subreportVariable="countItems" toVariable="grandCount" calculation="Sum"/>
Run Code Online (Sandbox Code Playgroud)