用JasperReport做报表,自己在做demo,但是输出的Integer没有问题,String却总是为null。
百思不得其解啊。希望做过的前辈给与指点。
用的是Struts2+JasperReport+IReportactionpackage com.demo.action;import java.util.ArrayList;
import java.util.List;import com.demo.javabean.Employee;
import com.demo.javabean.EmployeeFactory;
import com.demo.javabean.PeopleBean;
import com.opensymphony.xwork2.ActionSupport;public class DoReportAction extends ActionSupport{ /**
*
*/
private static final long serialVersionUID = 1L;
private List<Employee> myList; public String execute(){
Employee a1 = new Employee(1,11234,"IT部","王华");
Employee a2 = new Employee(2,211,"网络部","刘涛");
Employee a3 = new Employee(3,32,"网络部","陈龙");
Employee a4 = new Employee(4,44,"业务部","张三");
Employee a5 = new Employee(5,55123,"IT部","李四");
myList = new ArrayList<Employee>();
myList.add(a1);
myList.add(a2);
myList.add(a3);
myList.add(a4);
myList.add(a5);
return SUCCESS;
}
public List<Employee> getMyList() {
return myList;
} public void setMyList(List<Employee> myList) {
this.myList = myList;
}
}
javabeanpackage com.demo.javabean;public class Employee {
private int eid;
private int did;
private String eName;
private String dName;
public Employee(int a, int b, String c, String d){
eid=a;
did=b;
eName=c;
dName=d;
}
public int getEid() {
return eid;
}
public void setEid(int eid) {
this.eid = eid;
}
public int getDid() {
return did;
}
public void setDid(int did) {
this.did = did;
}
public String geteName() {
return eName;
}
public void seteName(String eName) {
this.eName = eName;
}
public String getdName() {
return dName;
}
public void setdName(String dName) {
this.dName = dName;
}
}
struts.xml<?xml version="1.0" encoding="UTF-8" ?>
<!DOCTYPE struts PUBLIC "-//Apache Software Foundation//DTD Struts Configuration 2.1//EN" "http://struts.apache.org/dtds/struts-2.1.dtd"><struts>
<package name="default"
extends="struts-default,jasperreports-default">
<action name="PDF" class="com.demo.action.DoReportAction">
<result name="success" type="jasper">
<param name="location">
/jasper/demoReport.jasper
</param>
<param name="dataSource">myList</param>
<param name="format">PDF</param>
</result>
</action>
<action name="HTML" class="com.demo.action.DoReportAction">
<result name="success" type="jasper">
<param name="location">
/jasper/demoReport.jasper
</param>
<param name="dataSource">myList</param>
<param name="format">HTML</param>
</result>
</action>
<action name="XML" class="com.demo.action.DoReportAction">
<result name="success" type="jasper">
<param name="location">
/jasper/demoReport.jasper
</param>
<param name="dataSource">myList</param>
<param name="format">XML</param>
</result>
</action>
<action name="CSV" class="com.demo.action.DoReportAction">
<result name="success" type="jasper">
<param name="location">
/jasper/demoReport.jasper
</param>
<param name="dataSource">myList</param>
<param name="format">CSV</param>
</result>
</action>
<action name="XLS" class="com.demo.action.DoReportAction">
<result name="success" type="jasper">
<param name="location">
/jasper/demoReport.jasper
</param>
<param name="dataSource">myList</param>
<param name="format">XLS</param>
</result>
</action>
</package>
</struts> 如图所示。integer类型可以正常显示在生成的PDF中,String类型全部为空。
求助啊。希望遇到过这个问题的大神帮帮忙stringjasperreportstruts
百思不得其解啊。希望做过的前辈给与指点。
用的是Struts2+JasperReport+IReportactionpackage com.demo.action;import java.util.ArrayList;
import java.util.List;import com.demo.javabean.Employee;
import com.demo.javabean.EmployeeFactory;
import com.demo.javabean.PeopleBean;
import com.opensymphony.xwork2.ActionSupport;public class DoReportAction extends ActionSupport{ /**
*
*/
private static final long serialVersionUID = 1L;
private List<Employee> myList; public String execute(){
Employee a1 = new Employee(1,11234,"IT部","王华");
Employee a2 = new Employee(2,211,"网络部","刘涛");
Employee a3 = new Employee(3,32,"网络部","陈龙");
Employee a4 = new Employee(4,44,"业务部","张三");
Employee a5 = new Employee(5,55123,"IT部","李四");
myList = new ArrayList<Employee>();
myList.add(a1);
myList.add(a2);
myList.add(a3);
myList.add(a4);
myList.add(a5);
return SUCCESS;
}
public List<Employee> getMyList() {
return myList;
} public void setMyList(List<Employee> myList) {
this.myList = myList;
}
}
javabeanpackage com.demo.javabean;public class Employee {
private int eid;
private int did;
private String eName;
private String dName;
public Employee(int a, int b, String c, String d){
eid=a;
did=b;
eName=c;
dName=d;
}
public int getEid() {
return eid;
}
public void setEid(int eid) {
this.eid = eid;
}
public int getDid() {
return did;
}
public void setDid(int did) {
this.did = did;
}
public String geteName() {
return eName;
}
public void seteName(String eName) {
this.eName = eName;
}
public String getdName() {
return dName;
}
public void setdName(String dName) {
this.dName = dName;
}
}
struts.xml<?xml version="1.0" encoding="UTF-8" ?>
<!DOCTYPE struts PUBLIC "-//Apache Software Foundation//DTD Struts Configuration 2.1//EN" "http://struts.apache.org/dtds/struts-2.1.dtd"><struts>
<package name="default"
extends="struts-default,jasperreports-default">
<action name="PDF" class="com.demo.action.DoReportAction">
<result name="success" type="jasper">
<param name="location">
/jasper/demoReport.jasper
</param>
<param name="dataSource">myList</param>
<param name="format">PDF</param>
</result>
</action>
<action name="HTML" class="com.demo.action.DoReportAction">
<result name="success" type="jasper">
<param name="location">
/jasper/demoReport.jasper
</param>
<param name="dataSource">myList</param>
<param name="format">HTML</param>
</result>
</action>
<action name="XML" class="com.demo.action.DoReportAction">
<result name="success" type="jasper">
<param name="location">
/jasper/demoReport.jasper
</param>
<param name="dataSource">myList</param>
<param name="format">XML</param>
</result>
</action>
<action name="CSV" class="com.demo.action.DoReportAction">
<result name="success" type="jasper">
<param name="location">
/jasper/demoReport.jasper
</param>
<param name="dataSource">myList</param>
<param name="format">CSV</param>
</result>
</action>
<action name="XLS" class="com.demo.action.DoReportAction">
<result name="success" type="jasper">
<param name="location">
/jasper/demoReport.jasper
</param>
<param name="dataSource">myList</param>
<param name="format">XLS</param>
</result>
</action>
</package>
</struts> 如图所示。integer类型可以正常显示在生成的PDF中,String类型全部为空。
求助啊。希望遇到过这个问题的大神帮帮忙stringjasperreportstruts
demoReport.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="demoReport" pageWidth="595" pageHeight="842" columnWidth="555" leftMargin="20" rightMargin="20" topMargin="20" bottomMargin="20" uuid="c32e0947-3ddb-45e9-85ba-f96cc6181991">
<property name="ireport.zoom" value="1.0"/>
<property name="ireport.x" value="0"/>
<property name="ireport.y" value="0"/>
<property name="ireport.scriptlethandling" value="0"/>
<property name="ireport.encoding" value="UTF-8"/>
<import value="net.sf.jasperreports.engine.*"/>
<import value="java.util.*"/>
<import value="net.sf.jasperreports.engine.data.*"/>
<queryString language="SQL">
<![CDATA[]]>
</queryString>
<field name="dName" class="java.lang.String">
<fieldDescription><![CDATA[dName]]></fieldDescription>
</field>
<field name="eName" class="java.lang.String">
<fieldDescription><![CDATA[eName]]></fieldDescription>
</field>
<field name="did" class="java.lang.Integer">
<fieldDescription><![CDATA[did]]></fieldDescription>
</field>
<field name="eid" class="java.lang.Integer">
<fieldDescription><![CDATA[eid]]></fieldDescription>
</field>
<background>
<band splitType="Stretch"/>
</background>
<title>
<band height="79" splitType="Stretch">
<staticText>
<reportElement uuid="55efa1c6-2d29-484c-b9fd-7c610b6c8a8b" x="142" y="0" width="166" height="58"/>
<textElement>
<font fontName="宋体" size="24" pdfFontName="STSong-Light" pdfEncoding="UniGB-UCS2-H"/>
</textElement>
<text><![CDATA[报表]]></text>
</staticText>
</band>
</title>
<pageHeader>
<band height="35" splitType="Stretch"/>
</pageHeader>
<columnHeader>
<band height="61" splitType="Stretch">
<staticText>
<reportElement uuid="a3db2c53-88a5-4a69-96bb-4cf7f238d818" x="365" y="22" width="100" height="20"/>
<textElement>
<font pdfFontName="STSong-Light" pdfEncoding="UniGB-UCS2-H"/>
</textElement>
<text><![CDATA[部门名称]]></text>
</staticText>
<staticText>
<reportElement uuid="b1489210-5ab1-4e7b-a98a-029f713d7ec0" x="123" y="22" width="100" height="20"/>
<textElement>
<font pdfFontName="STSong-Light" pdfEncoding="UniGB-UCS2-H"/>
</textElement>
<text><![CDATA[员工姓名]]></text>
</staticText>
<staticText>
<reportElement uuid="97fce1fb-6b97-47ae-b9b3-786cdff6c620" x="0" y="22" width="100" height="20"/>
<textElement>
<font fontName="宋体" pdfFontName="STSong-Light" pdfEncoding="UniGB-UCS2-H"/>
</textElement>
<text><![CDATA[员工id ]]></text>
</staticText>
<staticText>
<reportElement uuid="b85fc19e-1f3e-4409-8e92-68d2d527d651" x="240" y="22" width="100" height="20"/>
<textElement>
<font pdfFontName="STSong-Light" pdfEncoding="UniGB-UCS2-H"/>
</textElement>
<text><![CDATA[部门id]]></text>
</staticText>
</band>
</columnHeader>
<detail>
<band height="43" splitType="Stretch">
<textField isBlankWhenNull="false">
<reportElement uuid="d5235949-8103-4c91-8293-e7983267c262" key="textField-1" x="0" y="0" width="62" height="30"/>
<box>
<topPen lineWidth="0.0" lineStyle="Solid" lineColor="#000000"/>
<leftPen lineWidth="0.0" lineStyle="Solid" lineColor="#000000"/>
<bottomPen lineWidth="0.0" lineStyle="Solid" lineColor="#000000"/>
<rightPen lineWidth="0.0" lineStyle="Solid" lineColor="#000000"/>
</box>
<textElement>
<font fontName="宋体" size="14" pdfFontName="STSong-Light" pdfEncoding="UniGB-UCS2-H" isPdfEmbedded="true"/>
</textElement>
<textFieldExpression><![CDATA[$F{eid}]]></textFieldExpression>
</textField>
<textField isBlankWhenNull="false">
<reportElement uuid="9530f3e6-8a2a-4dcb-8b3d-6ac9c83b82a4" key="textField-2" x="123" y="0" width="105" height="29"/>
<box>
<topPen lineWidth="0.0" lineStyle="Solid" lineColor="#000000"/>
<leftPen lineWidth="0.0" lineStyle="Solid" lineColor="#000000"/>
<bottomPen lineWidth="0.0" lineStyle="Solid" lineColor="#000000"/>
<rightPen lineWidth="0.0" lineStyle="Solid" lineColor="#000000"/>
</box>
<textElement>
<font fontName="宋体" size="14" pdfFontName="STSong-Light" pdfEncoding="UniGB-UCS2-H" isPdfEmbedded="true"/>
</textElement>
<textFieldExpression><![CDATA[$F{eName}]]></textFieldExpression>
</textField>
<textField isBlankWhenNull="false">
<reportElement uuid="cc617127-f059-4b7d-92a0-1ab0ea281bed" key="textField-3" x="240" y="0" width="100" height="28"/>
<box>
<topPen lineWidth="0.0" lineStyle="Solid" lineColor="#000000"/>
<leftPen lineWidth="0.0" lineStyle="Solid" lineColor="#000000"/>
<bottomPen lineWidth="0.0" lineStyle="Solid" lineColor="#000000"/>
<rightPen lineWidth="0.0" lineStyle="Solid" lineColor="#000000"/>
</box>
<textElement>
<font fontName="宋体" size="14" pdfFontName="STSong-Light" pdfEncoding="UniGB-UCS2-H" isPdfEmbedded="true"/>
</textElement>
<textFieldExpression><![CDATA[$F{did}]]></textFieldExpression>
</textField>
<textField isBlankWhenNull="false">
<reportElement uuid="0c030f20-2aae-4303-83f2-6472ce8bf697" key="textField-4" x="365" y="0" width="111" height="30"/>
<box>
<topPen lineWidth="0.0" lineStyle="Solid" lineColor="#000000"/>
<leftPen lineWidth="0.0" lineStyle="Solid" lineColor="#000000"/>
<bottomPen lineWidth="0.0" lineStyle="Solid" lineColor="#000000"/>
<rightPen lineWidth="0.0" lineStyle="Solid" lineColor="#000000"/>
</box>
<textElement>
<font fontName="宋体" size="14" pdfFontName="STSong-Light" pdfEncoding="UniGB-UCS2-H" isPdfEmbedded="true"/>
</textElement>
<textFieldExpression><![CDATA[$F{dName}]]></textFieldExpression>
</textField>
<line>
<reportElement uuid="e784c82d-038e-402d-99f5-356bb5bc7e73" key="line-1" x="-30" y="37" width="593" height="1"/>
</line>
</band>
</detail>
<columnFooter>
<band height="45" splitType="Stretch"/>
</columnFooter>
<pageFooter>
<band height="54" splitType="Stretch"/>
</pageFooter>
<summary>
<band height="42" splitType="Stretch"/>
</summary>
</jasperReport>
写不下了,在这里补上。
因为命名问题,eName,dName的get set方法不对,导致了jasperreport无法获得这两个属性。。
后来把N改为小写,把getset方法改成getEname,问题自然就解决了。。
分儿就给你了- -。