Java JasperReports连接

Java JasperReports连接,java,jasper-reports,Java,Jasper Reports,我正在尝试导出我的数据表,为此我使用JasperReport, 但它不起作用。 我得到了这个错误: net.sf.jasperreports.engine.JRException: Error retrieving field value from bean 你能帮帮我吗 <?xml version="1.0" encoding="UTF-8"?> <jasperReport xmlns="http://jasperreports.sourceforge.net/ja

我正在尝试导出我的数据表,为此我使用JasperReport, 但它不起作用。 我得到了这个错误:

net.sf.jasperreports.engine.JRException: Error retrieving field value from bean
你能帮帮我吗

  <?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="null" language="groovy" pageWidth="842" pageHeight="595" orientation="Landscape" columnWidth="802" 
          leftMargin="20" rightMargin="20" topMargin="20" bottomMargin="20" >
<style name="Title" fontName="Times New Roman" fontSize="50" isBold="true" pdfFontName="Times-Bold"/>
<style name="SubTitle" forecolor="#736343" fontName="Arial" fontSize="18"/>
<style name="Column header" forecolor="#666666" fontName="Arial" fontSize="12" isBold="true"/>
<style name="Detail" fontName="Arial" fontSize="12"/>
<style name="Row" mode="Transparent">
    <conditionalStyle>
        <conditionExpression><![CDATA[$V{REPORT_COUNT}%2 == 0]]></conditionExpression>
        <style backcolor="#E6DAC3"/>
    </conditionalStyle>
</style>
<queryString language="HQL">
    <![CDATA[SELECT
 article.`CODE_ARTICLE` AS article_CODE_ARTICLE,
 article.`DESIGNATIONAL` AS article_DESIGNATIONAL,
 article.`DESIGNATIONFR` AS article_DESIGNATIONFR
FROM
 `article` article]]>
</queryString>
<field name="article_CODE_ARTICLE" class="java.lang.String"/>
<field name="article_DESIGNATIONAL" class="java.lang.String"/>
<field name="article_DESIGNATIONFR" class="java.lang.String"/>
<background>
    <band splitType="Stretch"/>
</background>
<title>
    <band height="136" splitType="Stretch">

        <staticText>
            <reportElement style="Title" x="270" y="0" width="263" height="62"/>
            <textElement verticalAlignment="Middle">
                <font pdfFontName="Times-Roman"/>
            </textElement>
            <text><![CDATA[Articles]]></text>
        </staticText>



    </band>
</title>
<pageHeader>
    <band splitType="Stretch"/>
</pageHeader>
<columnHeader>
    <band height="16" splitType="Stretch">
        <line>
            <reportElement positionType="FixRelativeToBottom" x="0" y="15" width="802" height="1" />
            <graphicElement>
                <pen lineWidth="0.5" lineColor="#999999"/>
            </graphicElement>
        </line>
        <staticText>
            <reportElement style="Column header" x="0" y="0" width="267" height="15" forecolor="#736343" />
            <text><![CDATA[article_CODE_ARTICLE]]></text>
        </staticText>
        <staticText>
            <reportElement style="Column header" x="267" y="0" width="267" height="15" forecolor="#736343" />
            <text><![CDATA[article_DESIGNATIONAL]]></text>
        </staticText>
        <staticText>
            <reportElement style="Column header" x="534" y="0" width="267" height="15" forecolor="#736343" />
            <text><![CDATA[article_DESIGNATIONFR]]></text>
        </staticText>
    </band>
</columnHeader>
<detail>
    <band height="15" splitType="Stretch">
        <frame>
            <reportElement style="Row" mode="Opaque" x="0" y="0" width="802" height="15"/>
            <textField isStretchWithOverflow="true">
                <reportElement style="Detail" x="0" y="0" width="267" height="15"/>
                <textFieldExpression><![CDATA[$F{article_CODE_ARTICLE}]]></textFieldExpression>
            </textField>
            <textField isStretchWithOverflow="true">
                <reportElement style="Detail" x="267" y="0" width="267" height="15"/>
                <textFieldExpression><![CDATA[$F{article_DESIGNATIONAL}]]></textFieldExpression>
            </textField>
            <textField isStretchWithOverflow="true">
                <reportElement style="Detail" x="534" y="0" width="267" height="15"/>
                <textFieldExpression><![CDATA[$F{article_DESIGNATIONFR}]]></textFieldExpression>
            </textField>
        </frame>
    </band>
</detail>
<columnFooter>
    <band height="6" splitType="Stretch">
        <line>
            <reportElement positionType="FixRelativeToBottom" x="0" y="3" width="802" height="1" />
            <graphicElement>
                <pen lineWidth="0.5" lineColor="#999999"/>
            </graphicElement>
        </line>
    </band>
</columnFooter>
<pageFooter>
    <band height="25" splitType="Stretch">
        <frame>
            <reportElement mode="Opaque" x="-21" y="1" width="843" height="24" forecolor="#D0B48E" backcolor="#F2EBDF" />
            <textField evaluationTime="Report">
                <reportElement style="Column header" x="783" y="1" width="40" height="20" forecolor="#736343" />
                <textElement verticalAlignment="Middle">
                    <font size="10" isBold="false"/>
                </textElement>
                <textFieldExpression><![CDATA[" " + $V{PAGE_NUMBER}]]></textFieldExpression>
            </textField>
            <textField>
                <reportElement style="Column header" x="703" y="1" width="80" height="20" forecolor="#736343" />
                <textElement textAlignment="Right" verticalAlignment="Middle">
                    <font size="10" isBold="false"/>
                </textElement>
                <textFieldExpression><![CDATA["Page "+$V{PAGE_NUMBER}+" of"]]></textFieldExpression>
            </textField>
            <textField pattern="EEEEE dd MMMMM yyyy">
                <reportElement style="Column header" x="22" y="1" width="197" height="20" forecolor="#736343"/>
                <textElement verticalAlignment="Middle">
                    <font size="10" isBold="false"/>
                </textElement>
                <textFieldExpression><![CDATA[new java.util.Date()]]></textFieldExpression>
            </textField>
        </frame>
    </band>
</pageFooter>
<summary>
    <band splitType="Stretch"/>
</summary>

当jasper report无法使用作为数据源传递的bean中的字段名访问公共getter时抛出

您需要在
bean
中通过
articleDAO.findAll()
方法

public String getArticle_CODE_ARTICLE(){//your code}
public String getArticle_DESIGNATIONAL(){//your code}
public String getArticle_DESIGNATIONFR(){//your code}
既然你有这些字段

<field name="article_CODE_ARTICLE" class="java.lang.String"/>
<field name="article_DESIGNATIONAL" class="java.lang.String"/>
<field name="article_DESIGNATIONFR" class="java.lang.String"/>

请注意:

<queryString language="HQL">
<![CDATA[SELECT
article.`CODE_ARTICLE` AS article_CODE_ARTICLE,
article.`DESIGNATIONAL` AS article_DESIGNATIONAL,
article.`DESIGNATIONFR` AS article_DESIGNATIONFR
FROM
 `article` article]]>
</queryString>

由于您正在传递一个
JRBeanCollectionDataSource
,因此不考虑它,如果您希望考虑它,则需要传递
Hibernate连接
(以及jasper report的其他配置以了解您的映射)

<field name="article_CODE_ARTICLE" class="java.lang.String"/>
<field name="article_DESIGNATIONAL" class="java.lang.String"/>
<field name="article_DESIGNATIONFR" class="java.lang.String"/>
<queryString language="HQL">
<![CDATA[SELECT
article.`CODE_ARTICLE` AS article_CODE_ARTICLE,
article.`DESIGNATIONAL` AS article_DESIGNATIONAL,
article.`DESIGNATIONFR` AS article_DESIGNATIONFR
FROM
 `article` article]]>
</queryString>