============2005-08-27=======JasperReport 高级应用(结尾)
对于对读出的字段要做的一些处理,可以自己编写一个类的静态方法来实现,比如对于符号和中文的转换,可以写一个InstallCodeCHINESE.java的类,里面定义一个public的方法, public static String Convert(String str)
在使用的时候要带上包的路径,并且把要转换的字段放到里面,例如:
<textFieldExpression class="java.lang.String">
com.sincetimes.util.InstallCodeCHINESE.Convert($F{install_code})
</textFieldExpression>
到这里,JasperReport的使用中用到的大部分东西应该都有了,这里我贴上一个例子,里面用到了基本所有的东西,当然这个要是想要运行,必须在框架的基础上,要运行的时候,输入:
staticInstallCode.xml
<?xml version="1.0" encoding="GB2312"?>
<!DOCTYPE jasperReport PUBLIC "-//JasperReports//DTD Report Design//EN" "http://jasperreports.sourceforge.net/dtds/jasperreport.dtd">
<!--
This report template is used to collect statistic data about downloading. The report is intended for SP.
xmmen modified 2003-08-12
-->
<jasperReport name="staticInstallCode" pageWidth="595" pageHeight="842" columnWidth="555" columnSpacing="0" leftMargin="20" rightMargin="20" topMargin="30" bottomMargin="30" whenNoDataType="AllSectionsNoDetail">
<reportFont name="SimSung" isDefault="true" fontName="SimSung" size="12" pdfFontName="STSong-Light" pdfEncoding="UniGB-UCS2-H" isPdfEmbedded="false"/>
<reportFont name="SimSung_Bold" isDefault="false" fontName="SimSung" size="12" isBold="true" pdfFontName="STSong-Light" pdfEncoding="UniGB-UCS2-H" isPdfEmbedded="false"/>
<reportFont name="SimSung_Italic" isDefault="false" fontName="SimSung" size="12" isItalic="true" pdfFontName="STSong-Light" pdfEncoding="UniGB-UCS2-H" isPdfEmbedded="false"/>
<reportFont name="Arial_Normal" isDefault="true" fontName="Arial" size="12" pdfFontName="Helvetica" pdfEncoding="Cp1252" isPdfEmbedded="false"/>
<reportFont name="Arial_Bold" isDefault="false" fontName="Arial" size="12" isBold="true" pdfFontName="Helvetica-Bold" pdfEncoding="Cp1252" isPdfEmbedded="false"/>
<reportFont name="Arial_Italic" isDefault="false" fontName="Arial" size="12" isItalic="true" pdfFontName="Helvetica-Oblique" pdfEncoding="Cp1252" isPdfEmbedded="false"/>
<parameter name="startTime" class="java.lang.String">
<defaultValueExpression>
<![CDATA[new java.text.SimpleDateFormat("yyyy-MM-dd").format(new java.util.Date())]]>
</defaultValueExpression>
</parameter>
<parameter name="endTime" class="java.lang.String">
<defaultValueExpression>
<![CDATA[new java.text.SimpleDateFormat("yyyy-MM-dd").format(new java.util.Date())]]>
</defaultValueExpression>
</parameter>
<!--
Define the default parameters everytime JasperReportServlet will hand in.
-->
<parameter name="SERVER_HOST_PARAM" class="java.lang.String">
<defaultValueExpression>
"localhost"
</defaultValueExpression>
</parameter>
<parameter name="SERVER_PORT_PARAM" class="java.lang.String">
<defaultValueExpression>
"80"
</defaultValueExpression>
</parameter>
<parameter name="SERVLET_CONTEXT_PARAM" class="java.lang.String">
<defaultValueExpression>
"/jasperreports"
</defaultValueExpression>
</parameter>
<parameter name="SERVLET_NAME_PARAM" class="java.lang.String">
<defaultValueExpression>
"/jasper"
</defaultValueExpression>
</parameter>
<parameter name="STATIC_RESOUCE_PARAM" class="java.lang.String">
<defaultValueExpression>
"images/"
</defaultValueExpression>
</parameter>
<parameter name="REQUEST_URI_PARAM" class="java.lang.String"/>
<parameter name="QUERY_STRING_PARAM" class="java.lang.String"/>
<parameter name="PATH_INFO_PARAM" class="java.lang.String"/>
<parameter name="CURRENT_PAGE_PARAM" class="java.lang.Integer"/>
<queryString><![CDATA[
select install_code ,download_date,count(*) as count_num from push_result
where download_date>'2005-08-01'
and download_date<'2005-09-01'
group by install_code;
]]></queryString>
<field name="install_code" class="java.lang.String"/>
<field name="count_num" class="java.lang.String"/>
<field name="download_date" class="java.lang.String"/>
<!--
Define the variable that whole report will heavily uses.
-->
<variable name="serverUrl" class="java.lang.String" resetType="Report">
<variableExpression>"P{SERVER_HOST_PARAM}+":"+$P{SERVER_PORT_PARAM}+$P{SERVLET_CONTEXT_PARAM}</variableExpression]http://"+$P{SERVER_HOST_PARAM}+":"+$P{SERVER_PORT_PARAM}+$P{SERVLET_CONTEXT_PARAM}</variableExpression>
<initialValueExpression>"P{SERVER_HOST_PARAM}+":"+$P{SERVER_PORT_PARAM}+$P{SERVLET_CONTEXT_PARAM}</initialValueExpression]http://"+$P{SERVER_HOST_PARAM}+":"+$P{SERVER_PORT_PARAM}+$P{SERVLET_CONTEXT_PARAM}</initialValueExpression>
</variable>
<title>
<band height="130">
<elementGroup>
<line>
<reportElement x="0" y="0" width="555" height="0" forecolor="black"/>
<graphicElement stretchType="NoStretch"/>
</line>
<image scaleImage="Clip">
<reportElement x="5" y="5" width="120" height="120"/>
<imageExpression class="java.lang.String"><![CDATA["D:\\iReport-0.5.0\\MyReports\\Water lilies.jpg"]]></imageExpression>
</image>
</elementGroup>
<staticText>
<reportElement x="170" y="5" width="375" height="55"/>
<textElement textAlignment="Right" lineSpacing="Single">
<font reportFont="SimSung" size="20"/>
</textElement>
<text>报表--统计游戏状态次数</text>
</staticText>
<staticText>
<reportElement x="170" y="60" width="375" height="20"/>
<textElement textAlignment="Right" lineSpacing="Single">
<font reportFont="SimSung" size="12"/>
</textElement>
<text>(c)2001-2005 中国移动</text>
</staticText>
<textField evaluationTime="Report">
<reportElement x="210" y="100" width="350" height="25"/>
<textElement textAlignment="Justified" verticalAlignment="Top" lineSpacing="Single">
<font fontName="SimSun_Italic" size="12"/>
</textElement>
<textFieldExpression class="java.lang.String">"本报表共包含"+$V{REPORT_COUNT}+"条统计记录("+$P{startTime}+"至"+$P{endTime}+")"</textFieldExpression>
</textField>
</band>
</title>
<pageHeader>
<band height="25">
<rectangle>
<reportElement x="0" y="5" width="555" height="20" forecolor="#333333" backcolor="#333333"/>
<graphicElement stretchType="NoStretch"/>
</rectangle>
<staticText>
<reportElement x="0" y="7" width="200" height="18" forecolor="white" backcolor="#333333" mode="Opaque" isPrintInFirstWholeBand="true"/>
<textElement textAlignment="Left">
<font reportFont="SimSung_Bold"/>
</textElement>
<text>状态说明</text>
</staticText>
<staticText>
<reportElement x="200" y="7" width="200" height="18" forecolor="white" backcolor="#333333" mode="Opaque" />
<textElement textAlignment="Center">
<font reportFont="SimSung_Bold"/>
</textElement>
<text>次数</text>
</staticText>
<staticText>
<reportElement x="400" y="7" width="155" height="18" forecolor="white" backcolor="#333333" mode="Opaque"/>
<textElement textAlignment="Right">
<font reportFont="SimSung_Bold"/>
</textElement>
<text>最近一次时间</text>
</staticText>
</band>
</pageHeader>
<detail>
<band height="25">
<textField hyperlinkType="Reference">
<reportElement x="0" y="4" width="200" height="20" isPrintRepeatedValues="false" isPrintInFirstWholeBand="true"/>
<textElement textAlignment="Left">
<font fontName="SimSung" pdfFontName="STSong-Light" pdfEncoding="UniGB-UCS2-H" isPdfEmbedded="false"/>
</textElement>
<textFieldExpression class="java.lang.String">
com.sincetimes.util.InstallCodeCHINESE.Convert($F{install_code})
</textFieldExpression>
</textField>
<textField hyperlinkType="Reference">
<reportElement x="200" y="4" width="200" height="20" isPrintRepeatedValues="true"/>
<textElement textAlignment="Center">
<font fontName="SimSung" pdfFontName="STSong-Light" pdfEncoding="UniGB-UCS2-H" isPdfEmbedded="false"/>
</textElement>
<textFieldExpression class="java.lang.String">
$F{count_num}
</textFieldExpression>
</textField>
<textField hyperlinkType="Reference">
<reportElement x="400" y="4" width="155" height="20" isPrintRepeatedValues="true"/>
<textElement textAlignment="Right">
<font fontName="SimSung" pdfFontName="STSong-Light" pdfEncoding="UniGB-UCS2-H" isPdfEmbedded="false"/>
</textElement>
<textFieldExpression class="java.lang.String">
$F{download_date}
</textFieldExpression>
</textField>
<line>
<reportElement x="0" y="24" width="555" height="0" forecolor="#808080" positionType="Float"/>
<graphicElement stretchType="NoStretch"/>
</line>
</band>
</detail>
<pageFooter>
<band height="50">
<textField hyperlinkType="Reference" isStretchWithOverflow="true" evaluationTime="Report">
<reportElement x="100" y="15" width="100" height="20" isPrintRepeatedValues="false"/>
<textElement textAlignment="Right">
<font fontName="SimSung" pdfFontName="STSong-Light" pdfEncoding="UniGB-UCS2-H" isPdfEmbedded="false"/>
</textElement>
<textFieldExpression class="java.lang.String">
"共"+$V{PAGE_NUMBER}+"页"
</textFieldExpression>
</textField>
<textField hyperlinkType="Reference" isStretchWithOverflow="true" evaluationTime="Now">
<reportElement x="200" y="15" width="155" height="20" isPrintRepeatedValues="false"/>
<textElement textAlignment="Right">
<font fontName="SimSung" pdfFontName="STSong-Light" pdfEncoding="UniGB-UCS2-H" isPdfEmbedded="false"/>
</textElement>
<textFieldExpression class="java.lang.String">
"第"+$V{PAGE_NUMBER}+"页"
</textFieldExpression>
</textField>
</band>
</pageFooter>
<summary>
<band height="60">
<textField isStretchWithOverflow="true">
<reportElement x="175" y="20" width="180" height="15"/>
<textElement textAlignment="Center">
<font reportFont="SimSung"/>
</textElement>
<textFieldExpression class="java.lang.String">
"本报表统计应用的用户访问情况"+$V{serverUrl}
</textFieldExpression>
</textField>
</band>
</summary>
</jasperReport>
框架的话,有机会我会贴出来。