在上一篇博客里面已经讲了IReport设置数据源的问题。在本博客中将讲述如何使用数据源。
?
?
?
这个时候就可以从左边的Fileds中选择相应的Filed托到右边的设计页面中
?
?
生成的预览界面:
对应的xml文件:
<?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="report3" language="groovy" pageWidth="595" pageHeight="842" whenNoDataType="AllSectionsNoDetail" 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"/> <queryString> <![CDATA[select * from t_blog;]]> </queryString> <field name="id" class="java.lang.Integer"/> <field name="content" class="java.lang.String"/> <field name="postTime" class="java.sql.Timestamp"/> <field name="seenCount" class="java.lang.Integer"/> <field name="title" class="java.lang.String"/> <field name="blogStore" class="java.lang.Integer"/> <field name="owner" class="java.lang.Integer"/> <field name="sysCategory" class="java.lang.Integer"/> <background> <band splitType="Stretch"/> </background> <title> <band height="44" splitType="Stretch"> <staticText> <reportElement x="227" y="12" width="100" height="20" forecolor="#FF0000"/> <textElement textAlignment="Center"> <font size="13" isBold="true"/> </textElement> <text><![CDATA[标题]]></text> </staticText> </band> </title> <pageHeader> <band height="35" splitType="Stretch"> <staticText> <reportElement x="227" y="15" width="100" height="20" forecolor="#FF0000"/> <textElement textAlignment="Center"> <font size="13" isBold="true"/> </textElement> <text><![CDATA[页眉]]></text> </staticText> </band> </pageHeader> <columnHeader> <band height="40" splitType="Stretch"> <staticText> <reportElement x="70" y="2" width="100" height="20"/> <textElement/> <text><![CDATA[id]]></text> </staticText> <staticText> <reportElement x="214" y="2" width="100" height="20"/> <textElement/> <text><![CDATA[title]]></text> </staticText> <staticText> <reportElement x="373" y="2" width="100" height="20"/> <textElement/> <text><![CDATA[postTime]]></text> </staticText> </band> </columnHeader> <detail> <band height="81" splitType="Stretch"> <textField> <reportElement x="70" y="24" width="100" height="20"/> <textElement/> <textFieldExpression><![CDATA[$F{id}]]></textFieldExpression> </textField> <textField> <reportElement x="214" y="25" width="100" height="20"/> <textElement/> <textFieldExpression><![CDATA[$F{title}]]></textFieldExpression> </textField> <textField> <reportElement x="373" y="26" width="100" height="20"/> <textElement/> <textFieldExpression><![CDATA[$F{postTime}]]></textFieldExpression> </textField> </band> </detail> <columnFooter> <band height="40" splitType="Stretch"> <staticText> <reportElement x="227" y="10" width="100" height="20" forecolor="#FF0000"/> <textElement textAlignment="Center"> <font size="13" isBold="true"/> </textElement> <text><![CDATA[相当于表尾]]></text> </staticText> </band> </columnFooter> <pageFooter> <band height="43" splitType="Stretch"> <staticText> <reportElement x="227" y="13" width="100" height="20" forecolor="#FF0000"/> <textElement textAlignment="Center"> <font size="13" isBold="true"/> </textElement> <text><![CDATA[页脚]]></text> </staticText> </band> </pageFooter> <summary> <band height="41" splitType="Stretch"> <staticText> <reportElement x="227" y="10" width="100" height="20" forecolor="#FF0000"/> <textElement textAlignment="Center"> <font size="13" isBold="true"/> </textElement> <text><![CDATA[用于存放一些统计信息的]]></text> </staticText> </band> </summary> </jasperReport>?
?
?
?