如何在Jasper Report中显示多个Arraylists?

时间:2016-09-08 10:31:35

标签: java jasper-reports

我是jasper报告的新手,我想在我的jasper报告中显示多个列表...

projectreport.jrxml

<?xml version="1.0" encoding="UTF-8"?>
<!-- Created with Jaspersoft Studio version 6.3.0.final using JasperReports Library version 6.3.0  -->
<!-- 2016-09-08T15:19:00 -->
<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="projectreport" pageWidth="595" pageHeight="842" columnWidth="555" leftMargin="20" rightMargin="20" topMargin="20" bottomMargin="20" uuid="a36251ec-d165-4ea4-8259-065cebd6fb88">
    <property name="com.jaspersoft.studio.data.defaultdataadapter" value="One Empty Record"/>
    <queryString>
        <![CDATA[]]>
    </queryString>
    <field name="projectname" class="java.lang.String"/>
    <field name="contractammount" class="java.lang.Double"/>
    <field name="projecttype" class="java.lang.String"/>
    <field name="projectcustomer" class="java.lang.String"/>
    <field name="projectdesc" class="java.lang.String"/>
    <field name="startdate" class="java.lang.String"/>
    <field name="start_date" class="java.util.Date"/>
    <field name="enddate" class="java.util.Date"/>
    <field name="completionstatus" class="java.lang.String"/>
    <field name="completionstatusdate" class="java.util.Date"/>
    <field name="cons_type" class="java.lang.String"/>
    <field name="consdesc" class="java.lang.String"/>
    <background>
        <band splitType="Stretch"/>
    </background>
    <title>
        <band height="40" splitType="Stretch">
            <staticText>
                <reportElement x="250" y="10" width="100" height="30" uuid="0cba4304-4afe-4705-889f-c9455a25aaf8"/>
                <textElement>
                    <font fontName="SansSerif" size="18" isBold="true"/>
                </textElement>
                <text><![CDATA[Project]]></text>
            </staticText>
        </band>
    </title>
    <pageHeader>
        <band height="154" splitType="Stretch">
            <staticText>
                <reportElement x="0" y="7" width="70" height="13" uuid="b4002248-346f-4e4f-87ea-1e8c0bc20ae8"/>
                <textElement>
                    <font size="10"/>
                </textElement>
                <text><![CDATA[Name]]></text>
            </staticText>
            <textField>
                <reportElement x="90" y="10" width="100" height="20" uuid="e5612716-c6cc-4b60-a916-dec63412557c"/>
                <textFieldExpression><![CDATA[$F{projectname}]]></textFieldExpression>
            </textField>
            <staticText>
                <reportElement x="0" y="30" width="80" height="30" uuid="e90cc6b8-6e27-44b3-b9c4-189415a79faa"/>
                <text><![CDATA[Total Contract Ammount]]></text>
            </staticText>
            <textField>
                <reportElement x="90" y="30" width="100" height="20" uuid="e308a4f0-1d8f-40c7-81c2-4ca6db67be73"/>
                <textFieldExpression><![CDATA[$F{contractammount}]]></textFieldExpression>
            </textField>
            <staticText>
                <reportElement x="0" y="60" width="70" height="20" uuid="5993e836-bbcf-4925-8155-c8538139bb59"/>
                <text><![CDATA[Type]]></text>
            </staticText>
            <textField>
                <reportElement x="90" y="60" width="100" height="20" uuid="d3e5dc53-3970-4f39-8133-8face03e12f8"/>
                <textFieldExpression><![CDATA[$F{projecttype}]]></textFieldExpression>
            </textField>
            <staticText>
                <reportElement x="0" y="90" width="70" height="20" uuid="a5174c35-70ca-4ff0-acd6-8c3255e0885d"/>
                <text><![CDATA[Customer]]></text>
            </staticText>
            <textField>
                <reportElement x="90" y="90" width="100" height="20" uuid="beed5968-7eb6-4f8a-8074-b4fb3f67dd6d"/>
                <textFieldExpression><![CDATA[$F{projectcustomer}]]></textFieldExpression>
            </textField>
            <staticText>
                <reportElement x="-1" y="110" width="71" height="30" uuid="f4794615-9ded-4bc8-a172-be3b9c1f36be"/>
                <text><![CDATA[Description]]></text>
            </staticText>
            <textField>
                <reportElement x="90" y="110" width="461" height="40" uuid="95b69531-f143-45b4-ab25-0405e2ae9f52"/>
                <textFieldExpression><![CDATA[$F{projectdesc}]]></textFieldExpression>
            </textField>
        </band>
    </pageHeader>
    <columnHeader>
        <band height="84" splitType="Stretch">
            <line>
                <reportElement x="0" y="6" width="551" height="5" uuid="a4fab58e-f047-409d-bde7-65301f9c3adf"/>
            </line>
            <staticText>
                <reportElement x="150" y="10" width="280" height="30" uuid="1fe0e815-52cc-41a7-a66b-a34860d7cd86"/>
                <textElement>
                    <font fontName="SansSerif" size="18" isBold="true"/>
                </textElement>
                <text><![CDATA[Project Construction Schedule]]></text>
            </staticText>
            <staticText>
                <reportElement x="2" y="50" width="48" height="20" uuid="1447568d-37d6-4365-aaa6-e32a4016a746"/>
                <text><![CDATA[Start Date]]></text>
            </staticText>
            <staticText>
                <reportElement x="80" y="50" width="48" height="20" uuid="a4f661a4-a05d-4b5a-9a43-da401b703cee"/>
                <text><![CDATA[End Date]]></text>
            </staticText>
            <staticText>
                <reportElement x="400" y="50" width="48" height="20" uuid="1a832f82-0949-4de8-b18f-f4c392671227"/>
                <text><![CDATA[Type]]></text>
            </staticText>
            <staticText>
                <reportElement x="490" y="50" width="61" height="20" uuid="cbdd4c82-99b6-4562-adae-cdc0c8a49b78"/>
                <text><![CDATA[Description]]></text>
            </staticText>
            <staticText>
                <reportElement x="270" y="50" width="110" height="20" uuid="9724497b-d1de-44ad-a308-5aefb21e17e3"/>
                <text><![CDATA[Completion Status Date]]></text>
            </staticText>
            <staticText>
                <reportElement x="160" y="50" width="90" height="20" uuid="6dd565b7-2a7b-41ee-8c80-ea2135db4f6e"/>
                <text><![CDATA[Completion Status]]></text>
            </staticText>
        </band>
    </columnHeader>
    <detail>
        <band height="292" splitType="Stretch">
            <textField>
                <reportElement x="1" y="10" width="68" height="22" uuid="dd528090-8fa6-4bf4-aae5-7cdf9eefb9fa"/>
                <textFieldExpression><![CDATA[$F{start_date}]]></textFieldExpression>
            </textField>
            <textField>
                <reportElement x="80" y="10" width="60" height="20" uuid="68bec7f2-3e73-4d72-891b-a580e1f1db45"/>
                <textFieldExpression><![CDATA[$F{enddate}]]></textFieldExpression>
            </textField>
            <textField>
                <reportElement x="160" y="10" width="100" height="22" uuid="336f0769-5824-4dd7-9db0-e573088b4424"/>
                <textFieldExpression><![CDATA[$F{completionstatus}]]></textFieldExpression>
            </textField>
            <textField>
                <reportElement x="270" y="10" width="120" height="22" uuid="9713b02e-bfeb-471f-8bc1-08e2fe367b64"/>
                <textFieldExpression><![CDATA[$F{completionstatusdate}]]></textFieldExpression>
            </textField>
            <textField>
                <reportElement x="400" y="10" width="70" height="24" uuid="56ea37e9-01f8-48b8-9a8e-8f5ddfaa9215"/>
                <textFieldExpression><![CDATA[$F{cons_type}]]></textFieldExpression>
            </textField>
            <textField>
                <reportElement x="480" y="10" width="71" height="24" uuid="82f304c4-c248-490b-a54d-edfc9ac4d64f"/>
                <textFieldExpression><![CDATA[$F{consdesc}]]></textFieldExpression>
            </textField>
            <line>
                <reportElement x="-5" y="46" width="549" height="1" uuid="8bafef6c-96c1-42b8-a0e4-34a9d43aec37"/>
            </line>
        </band>
    </detail>
    <columnFooter>
        <band height="22" splitType="Stretch"/>
    </columnFooter>
    <pageFooter>
        <band height="90" splitType="Stretch"/>
    </pageFooter>
    <summary>
        <band height="42" splitType="Stretch"/>
    </summary>
</jasperReport>

ProductReport

public class ProductReport
{
    @Autowired
    BuilderProjectService builderProjectService;

    public List<Map<String, ?>> allProjects()
    {
        int projectId = 17;
        List<Map<String, ?>> listProducts = new ArrayList<Map<String,?>>();


        for (BuilderProject project : builderProjectService.getProjectwithId( projectId ))
        {
            Map<String, Object> m = new HashMap<String, Object>();
            m.put( "projectname", project.getName() );
            m.put( "contractammount", project.getTotalContractAmount() );
            m.put( "projecttype", project.getBuilderType().getName() );
            m.put( "projectcustomer", project.getDebtorsMaster().getName() );
            m.put( "projectdesc", project.getDescription() );
            m.put( "consscheduleList", project.getBuilderProjectConstructionSchedules() );

            listProducts.add( m );
        }
        return listProducts;
    }
} 

控制器

@RequestMapping(value = "/report", method = GET)
    public String reportjsp(ModelMap modelMap) throws IOException {

        modelMap.put( "listProducts", productReport.allProjects() );
        return "report";

    }

报告JSP

<%@ page contentType="application/pdf"%>
<%@ page trimDirectiveWhitespaces="true"%>
<%@ page import="net.sf.jasperreports.engine.*"%>
<%@ page import="net.sf.jasperreports.engine.data.*"%>
<%@ page import="java.io.*"%>
<%@ page import="java.util.*"%>

<%
try {
    List<Map<String, ?>> datasource = (List<Map<String, ?>>) request.getAttribute( "listProducts" );
    JRDataSource jrDataSource = new JRBeanCollectionDataSource(datasource);



    String jrxmlFile = session.getServletContext().getRealPath("/reports/projectreport.jrxml");
    InputStream input = new FileInputStream(new File(jrxmlFile));

    //Generating the report

    JasperReport jasperReport = JasperCompileManager.compileReport(input);
    JasperPrint jasperPrint = JasperFillManager.fillReport(jasperReport, null, jrDataSource);

    //Exporting the report as a PDF

    JasperExportManager.exportReportToPdfStream(jasperPrint, response.getOutputStream());

}

catch (Exception e)
{
    System.out.println("Exception in PDF Report Printing");
    /* e.printStackTrace(  ); */
}
%>

现在我的问题是在产品报告中我发送一个列表,我想在项目施工计划下打印它怎么做? 问题也在图像中描述

enter image description here

0 个答案:

没有答案