【问题标题】:Jasper Report print group values in different pagesJasper Report 在不同页面中打印组值
【发布时间】:2013-11-20 17:41:12
【问题描述】:

我在使用 iReport 4.1.3 时遇到了这个基本问题。我有两个表“订单”和“订单详情”。 我将购物车中的各种产品映射到 order_details 中的每个订单。例如: 在我的订单表中:

order_id
123
456

在 order_details 表中我将有:
order_id product_id
123         abc1
123         abc2
第456章                                                                
第456章                                                                                            = 第456章                                        

我在 ireport 中创建了以下 jrxml:

    <?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="merchant_invoice" language="groovy" pageWidth="595" pageHeight="842" columnWidth="555" leftMargin="20" rightMargin="20" topMargin="20" bottomMargin="20">
        <property name="ireport.zoom" value="1.0"/>
        <property name="ireport.x" value="0"/>
        <property name="ireport.y" value="0"/>
        <parameter name="order_ids" class="java.lang.String">
            <defaultValueExpression><![CDATA[]]></defaultValueExpression>
        </parameter>
        <queryString>
            <![CDATA[select
    o.order_id,od.product_id
    from cscart_orders o
    inner join cscart_order_details od on od.order_id=o.order_id
    where o.order_id in ($P{order_ids})]]>
        </queryString>
        <field name="order_id" class="java.math.BigInteger"/>
        <field name="product_id" class="java.math.BigInteger"/>
        <group name="order_id_group" isStartNewPage="true" isReprintHeaderOnEachPage="true">
            <groupExpression><![CDATA[$F{order_id}]]></groupExpression>
            <groupHeader>
                <band height="25">
                    <textField>
                        <reportElement x="6" y="3" width="380" height="20"/>
                        <textElement/>
                        <textFieldExpression><![CDATA["header for order_id "+$F{order_id}]]></textFieldExpression>
                    </textField>
                </band>
            </groupHeader>
            <groupFooter>
                <band height="25">
                    <textField>
                        <reportElement x="8" y="3" width="291" height="20"/>
                        <textElement/>
                        <textFieldExpression><![CDATA["Footer for order id : "+$F{order_id}]]></textFieldExpression>
                    </textField>
                </band>
            </groupFooter>
        </group>
        <background>
            <band splitType="Stretch"/>
        </background>
        <detail>
            <band height="30" splitType="Stretch">
                <textField>
                    <reportElement x="8" y="4" width="270" height="20"/>
                    <textElement/>
                    <textFieldExpression><![CDATA["Products with id :"+$F{product_id}]]></textFieldExpression>
                </textField>
            </band>
        </detail>
    </jasperReport>

但是当我使用参数作为 '123,456' 预览它时,我只得到一个页面,其中仅包含第一个订单的详细信息,即订单 123。 我没有得到我在哪里做错了。 请帮忙。

【问题讨论】:

    标签: jasper-reports ireport


    【解决方案1】:

    如果您选择多个订单 ID,则查询应该是这样的

    select
    o.order_id,od.product_id
    from cscart_orders o
    inner join cscart_order_details od on od.order_id=o.order_id
    where $X{IN,o.order_id,order_ids}
    

    参数order_ids的类应该是“java.util.Collection”,也可以给出默认值表达式

     <parameter name="order_ids" class="java.util.Collection"> 
     <defaultValueExpression><![CDATA[new ArrayList(Arrays.asList(new String[] {"123","456"}))]]></defaultValueExpression>
    </parameter>
    

    【讨论】:

    • 我的框架是这样开发的,每个参数都只能作为字符串传递。此外,将参数作为集合传递仍然没有帮助。
    • 我已更新答案并尝试在 iReport 中为参数提供默认值表达式。
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多