JasperReport(2)——IReport使用数据源

在上一篇博客里面已经讲了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>
 

 

 

 

  • 大小: 27.9 KB
  • 大小: 59.8 KB
  • 大小: 51.9 KB
  • 大小: 15.4 KB
  • 大小: 11.4 KB
  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
要在 JSP 页面中使用 JasperReport,可以按照以下步骤: 1. 在你的项目中导入 JasperReport 的相关库文件。 2. 创建一个 JasperReport 报表模板文件,可以使用 JasperReport 的设计工具 iReport 进行创建。 3. 在 JSP 页面中编写代码,创建一个 JasperReport 报表,并填充数据。 4. 将 JasperReport 报表输出到指定的输出流。 下面是一个简单的示例代码,演示如何在 JSP 页面中使用 JasperReport: ```java <%@ page import="java.util.*" %> <%@ page import="java.io.*" %> <%@ page import="net.sf.jasperreports.engine.*" %> <%@ page import="net.sf.jasperreports.engine.export.*" %> <%@ page contentType="application/pdf" %> <% // 创建一个 JasperReport 报表 JasperReport jasperReport = JasperCompileManager.compileReport("report_template.jrxml"); // 填充数据 Map<String, Object> params = new HashMap<String, Object>(); params.put("parameter1", "value1"); params.put("parameter2", "value2"); JRDataSource dataSource = new JREmptyDataSource(); JasperPrint jasperPrint = JasperFillManager.fillReport(jasperReport, params, dataSource); // 输出 JasperReport 报表到指定的输出流 OutputStream out = response.getOutputStream(); JasperExportManager.exportReportToPdfStream(jasperPrint, out); %> ``` 在这个示例代码中,我们首先创建了一个 JasperReport 报表,并填充了一些数据。然后,我们将 JasperReport 报表输出到一个 PDF 文件中。在这个例子中,我们将 PDF 文件直接输出到了 JSP 页面的输出流中,因此最后生成的 PDF 文件将直接在浏览器中显示出来。

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值