欧美三区_成人在线免费观看视频_欧美极品少妇xxxxⅹ免费视频_a级毛片免费播放_鲁一鲁中文字幕久久_亚洲一级特黄

JasperReport(3)——Java簡單使用IReport生成的

系統 1830 0

先看看設計的報表樣式:


JasperReport(3)——Java簡單使用IReport生成的文件建立報表
?reportTitle是新添加的一個參數,而其他的id和name是通過數據源得到的Filed。IReport在設置參數的時候需要先在左邊新建一個parameter,然后再把該parameter托到右邊的設計欄中。

?

生成的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>

  

?

JasperReport在生成報表的時候可以直接操作jrxml文件,然后通過Java代碼編譯為.jasper文件,也可以直接操作IReport編譯好的.jasper文件,下面就是用的直接操作.jasper文件,注釋掉的是操作jrxml文件的。JasperReport可以把生成的報表導出為多種格式,下面導出的是普通的HTML。JasperReport在往模版里面設置參數值,是提供一個Map進行參數傳入的。

java代碼:

    import java.io.FileInputStream;
import java.io.FileNotFoundException;
import java.io.InputStream;
import java.sql.Connection;
import java.sql.DriverManager;
import java.sql.SQLException;
import java.util.HashMap;
import java.util.Map;

import net.sf.jasperreports.engine.JRException;
import net.sf.jasperreports.engine.JasperExportManager;
import net.sf.jasperreports.engine.JasperFillManager;
import net.sf.jasperreports.engine.JasperPrint;
import net.sf.jasperreports.engine.JasperReport;

public class Test2 {

	public static void main(String args[]) throws JRException, ClassNotFoundException, SQLException, FileNotFoundException {
		String fileName = "E:\\reports\\report2.jrxml";//直接操作生成的jrxml文件
		JasperReport jasperReport = null;
		JasperPrint jasperPrint = null;
//		jasperReport = JasperCompileManager.compileReport(fileName);//編譯jrxml文件
		InputStream inputStream = new FileInputStream("E:\\reports\\report2.jasper");
		Map<String, Object> parameters = new HashMap<String, Object>();//傳入參數
		parameters.put("reportTitle", "我的第一個程序");
//		jasperPrint = JasperFillManager.fillReport(jasperReport, parameters, getConnection());
		jasperPrint = JasperFillManager.fillReport(inputStream, parameters, getConnection());
		JasperExportManager.exportReportToHtmlFile(jasperPrint, "first.html");
	}
	
	public static Connection getConnection() throws ClassNotFoundException, SQLException {
		Connection conn = null;
		Class.forName("com.mysql.jdbc.Driver");
		conn = DriverManager.getConnection("jdbc:mysql://localhost/blog", "root", "root");
		return conn;
	}
	
}

  
?

導出的HTML預覽界面:


?

JasperReport(3)——Java簡單使用IReport生成的文件建立報表


更多文章、技術交流、商務合作、聯系博主

微信掃碼或搜索:z360901061

微信掃一掃加我為好友

QQ號聯系: 360901061

您的支持是博主寫作最大的動力,如果您喜歡我的文章,感覺我的文章對您有幫助,請用微信掃描下面二維碼支持博主2元、5元、10元、20元等您想捐的金額吧,狠狠點擊下面給點支持吧,站長非常感激您!手機微信長按不能支付解決辦法:請將微信支付二維碼保存到相冊,切換到微信,然后點擊微信右上角掃一掃功能,選擇支付二維碼完成支付。

【本文對您有幫助就好】

您的支持是博主寫作最大的動力,如果您喜歡我的文章,感覺我的文章對您有幫助,請用微信掃描上面二維碼支持博主2元、5元、10元、自定義金額等您想捐的金額吧,站長會非常 感謝您的哦!!!

發表我的評論
最新評論 總共0條評論
主站蜘蛛池模板: japanese xxxxhd| 亚洲精品福利在线 | 九七婷婷狠狠成人免费视频 | 国产91福利在线精品剧情尤物 | av官网在线 | 国产精品免费大片一区二区 | 亚洲精品日韩在线 | 日韩一区二区三区在线观看 | 男人的天堂亚洲 | av一区在线观看 | 成人免费淫片aa视频免费 | 免费观看av网站 | 538prom国产在线视频一区 | 国产精品日韩专区 | 婷婷国产在线观看 | 猫鼠游戏电影在线观看免费版 | 成年做羞羞免费观看视频网站 | 国产成+人+亚洲+欧美+日韩 | 亚洲国产精品热久久 | 新版天堂资源中文在线 | 久色伊人 | 三级毛片在线看 | 国产精品久久久久一区二区 | 亚洲电影免费 | 久草福利在线观看 | 青青青青娱乐 | 91久久亚洲国产成人精品性色 | 国产99久久精品一区二区永久免费 | 天天摸天天操免费播放小视频 | 欧美日韩国产在线 | 一级做a爱片久久 | 国产在线观看福利片 | 中国一级特黄 | 欧美一级色片 | 午夜视频在线观看免费视频 | 欧美精品38videos性欧美 | 国产区在线观看 | 91 视频网站| 狠狠综合久久av一区二区小说 | 日本午夜在线观看 | 亚洲午夜无码毛片AV久久 |