struts2 ireport jasperReport结合生成报表,产生的报表的数据都是NULL。。。。。怎么解决。。
struts2 ireport jasperReport结合生成报表,产生的报表的数据都是NULL。。。。。怎么解决。。
使用不用struts2就成功
代码如下:
sample.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="sample" language="groovy" pageWidth="595" pageHeight="842" columnWidth="555" leftMargin="20" rightMargin="20" topMargin="20" bottomMargin="20" uuid="d6d5d74a-2d35-4475-a775-cccb896788b0">
<property name="ireport.zoom" value="1.0"/>
<property name="ireport.x" value="0"/>
<property name="ireport.y" value="0"/>
<queryString>
<![CDATA[select * from goods]]>
</queryString>
<field name="id" class="java.lang.Integer">
<fieldDescription><![CDATA[]]></fieldDescription>
</field>
<field name="saleid" class="java.lang.Integer">
<fieldDescription><![CDATA[]]></fieldDescription>
</field>
<field name="goodname" class="java.lang.String">
<fieldDescription><![CDATA[]]></fieldDescription>
</field>
<field name="time" class="java.lang.String">
<fieldDescription><![CDATA[]]></fieldDescription>
</field>
<field name="price" class="java.lang.String">
<fieldDescription><![CDATA[]]></fieldDescription>
</field>
<field name="amount" class="java.lang.Integer">
<fieldDescription><![CDATA[]]></fieldDescription>
</field>
<field name="instruction" class="java.lang.String">
<fieldDescription><![CDATA[]]></fieldDescription>
</field>
<field name="model" class="java.lang.String">
<fieldDescription><![CDATA[]]></fieldDescription>
</field>
<field name="statustion" class="java.lang.String">
<fieldDescription><![CDATA[]]></fieldDescription>
</field>
<background>
<band splitType="Stretch"/>
</background>
<title>
<band height="79" splitType="Stretch">
<staticText>
<reportElement uuid="115e8b1c-095a-4d77-a33e-3785bf207e95" x="230" y="19" width="103" height="35"/>
<textElement textAlignment="Justified">
<font size="24"/>
</textElement>
<text><![CDATA[商品清单]]></text>
</staticText>
</band>
</title>
<pageHeader>
<band height="35" splitType="Stretch">
<staticText>
<reportElement uuid="a1e4529b-00e9-4904-9705-b87d7544ea2d" x="22" y="0" width="106" height="25"/>
<textElement>
<font size="18"/>
</textElement>
<text><![CDATA[商品]]></text>
</staticText>
</band>
</pageHeader>
<columnHeader>
<band height="61" splitType="Stretch">
<staticText>
<reportElement uuid="7743c29f-df73-4914-a877-2c054a9bdd36" x="32" y="2" width="61" height="20"/>
<textElement/>
<text><![CDATA[id]]></text>
</staticText>
<staticText>
<reportElement uuid="a0b22268-2afe-49e8-9728-488ca0f482f4" x="93" y="2" width="100" height="20"/>
<textElement/>
<text><![CDATA[goodname]]></text>
</staticText>
<staticText>
<reportElement uuid="6c330a7b-37eb-4e21-9c11-502cf3b69ecc" x="193" y="2" width="100" height="20"/>
<textElement/>
<text><![CDATA[time]]></text>
</staticText>
<staticText>
<reportElement uuid="b2844649-aa90-4f3b-8a16-212f8db9a534" x="293" y="2" width="100" height="20"/>
<textElement/>
<text><![CDATA[price]]></text>
</staticText>
<staticText>
<reportElement uuid="a5e09a89-d120-42ba-a6d9-05e4afdcf4ea" x="493" y="2" width="55" height="20"/>
<textElement/>
<text><![CDATA[amount]]></text>
</staticText>
<staticText>
<reportElement uuid="40df4ee6-9dc4-4bb5-8d52-e906acf41ad2" x="393" y="2" width="100" height="20"/>
<textElement/>
<text><![CDATA[statustion]]></text>
</staticText>
</band>
</columnHeader>
<detail>
<band height="43" splitType="Stretch">
<textField isBlankWhenNull="true">
<reportElement uuid="0b609d45-96d8-4d4c-aab3-925f875c9022" x="32" y="11" width="61" height="20"/>
<textElement>
<font fontName="仿宋"/>
</textElement>
<textFieldExpression><![CDATA[$F{id}]]></textFieldExpression>
</textField>
<textField>
<reportElement uuid="dc14ec59-bc33-44e7-9f78-fb2f30b286c8" x="93" y="11" width="100" height="20"/>
<textElement>
<font fontName="仿宋"/>
</textElement>
<textFieldExpression><![CDATA[$F{goodname}]]></textFieldExpression>
</textField>
<textField>
<reportElement uuid="0b37b31c-f9dc-441b-af99-513ddfc126cc" x="193" y="11" width="100" height="20"/>
<textElement>
<font fontName="仿宋"/>
</textElement>
<textFieldExpression><![CDATA[$F{time}]]></textFieldExpression>
</textField>
<textField>
<reportElement uuid="2b2d8c5b-078b-4091-af83-92eb90bd05a5" x="293" y="11" width="100" height="20"/>
<textElement>
<font fontName="仿宋"/>
</textElement>
<textFieldExpression><![CDATA[$F{price}]]></textFieldExpression>
</textField>
<textField>
<reportElement uuid="edc4fd5c-319a-41e4-9c95-69aa18cb1991" x="493" y="11" width="55" height="20"/>
<textElement>
<font fontName="仿宋"/>
</textElement>
<textFieldExpression><![CDATA[$F{amount}]]></textFieldExpression>
</textField>
<textField>
<reportElement uuid="30e9c7cb-5ae8-4143-8262-9176ebc0f8b9" x="393" y="11" width="100" height="20"/>
<textElement>
<font fontName="仿宋"/>
</textElement>
<textFieldExpression><![CDATA[$F{statustion}]]></textFieldExpression>
</textField>
</band>
</detail>
<columnFooter>
<band height="45" splitType="Stretch"/>
</columnFooter>
<pageFooter>
<band height="54" splitType="Stretch"/>
</pageFooter>
<summary>
<band height="42" splitType="Stretch"/>
</summary>
</jasperReport>
struts.xml
<package name="test" extends="struts-default,jasperreports-default">
<action name="toHtml" class="test.TestAction" method="execute">
<result name="success" type="jasper">
<param name="location">/jasper/sample.jasper</param>
<param name="dataSource">userList</param>
<param name="format">HTML</param>
</result>
<result name="error">
/info_error.jsp
</result>
</action>
<action name="toPdf" class="test.TestAction" method="execute">
<result name="success" type="jasper">
<param name="location">/jasper/sample.jasper</param>
<param name="dataSource">userList</param>
<param name="format">PDF</param>
</result>
<result name="error">
/info_error.jsp
</result>
</action>
<action name="toXml" class="test.TestAction" method="execute">
<result name="success" type="jasper">
<param name="location">/jasper/sample.jasper</param>
<param name="dataSource">userList</param>
<param name="format">XML</param>
</result>
<result name="error">
/info_error.jsp
</result>
</action>
<action name="toXls" class="test.TestAction" method="execute">
<result name="success" type="jasper">
<param name="location">/jasper/sample.jasper</param>
<param name="dataSource">userList</param>
<param name="format">XLS</param>
</result>
<result name="error">
/info_error.jsp
</result>
</action>
</package>
<package name="px" namespace="/images" extends="struts-default">
<action name="px">
<result>/images/px.gif</result>
</action>
</package>
jsp
<body>
<a href="test/toHtml.action">toHTML</a>
<br><a href="test/toPdf.action">toPDF</a>
<br><a href="test/toXml.action">toXML</a>
<br><a href="test/toXls.action">toXLS</a>
</body>
action
public class TestAction extends ActionSupport {
private static final long serialVersionUID = 1L;
private ArrayList<goods> userList;
public String execute() {
goodsImp gImp=new goodsImp();
userList=(ArrayList)gImp.getGoods(0,20,null,null,null);
return SUCCESS;
}
public ArrayList<goods> getUserList() {
return userList;
}
public void setUserList(ArrayList<goods> userList) {
this.userList = userList;
}
}
goods.java
package bean;
import javax.persistence.Entity;
import javax.persistence.GeneratedValue;
import javax.persistence.Id;
@Entity
public class goods {
private int id;
private int saleid;
private String goodname;
private String time;
private String price;
private int amount;
private String instruction;
private String model;
private String statustion;
public goods(int id,String goodname,String time,String price,String statustion,int amount){
this.id=id;
this.goodname=goodname;
this.time=time;
this.price=price;
this.amount=amount;
this.statustion=statustion;
}
public goods(int id,String goodname,String time,String price,int amount,String statustion){
this.id=id;
this.goodname=goodname;
this.time=time;
this.price=price;
this.amount=amount;
this.statustion=statustion;
}
public goods(){
}
public int getAmount() {
return amount;
}
public String getGoodname() {
return goodname;
}
@Id
@GeneratedValue
public int getId() {
return id;
}
public String getInstruction() {
return instruction;
}
public String getModel() {
return model;
}
public String getPrice() {
return price;
}
public int getSaleid() {
return saleid;
}
public String getStatustion() {
return statustion;
}
public String getTime() {
return time;
}
public void setAmount(int amount) {
this.amount = amount;
}
public void setGoodname(String goodname) {
this.goodname = goodname;
}
public void setId(int id) {
this.id = id;
}
public void setInstruction(String instruction) {
this.instruction = instruction;
}
public void setModel(String model) {
this.model = model;
}
public void setPrice(String price) {
this.price = price;
}
public void setSaleid(int saleid) {
this.saleid = saleid;
}
public void setStatustion(String statustion) {
this.statustion = statustion;
}
public void setTime(String time) {
this.time = time;
}
}
?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
怎么解决的啊亲。求案例分析