或者,您可以执行以下操作(使用 iReport):
- 根据用户名添加报表组,不添加组页眉和页脚
- 将报表检查器中的字段拖放到报表设计器的详细信息区域中。
- 选择
Text field
包含用户名的,在属性面板中取消选中打印重复值
生成的报告如下图所示。
附上 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="report6" language="groovy" pageWidth="595" pageHeight="842" columnWidth="555" leftMargin="20" rightMargin="20" topMargin="20" bottomMargin="20" uuid="9ecb5f72-ce8e-4b32-bc4b-124460d6d018">
<property name="ireport.zoom" value="1.0"/>
<property name="ireport.x" value="0"/>
<property name="ireport.y" value="0"/>
<queryString>
<![CDATA[select * from (
select 'xmen' as username, 'news' as category, 'good' as view
union select 'xmen', 'media', 'good'
union select 'xmen', 'radio', 'bad'
union select 'xmen', 'tv', 'ok'
union select 'Ymen', 'news', 'good'
union select 'Ymen', 'media', 'good'
union select 'Ymen', 'radio', 'bad'
union select 'Ymen', 'tv', 'ok'
) tbl
order by username]]>
</queryString>
<field name="username" class="java.lang.String"/>
<field name="category" class="java.lang.String"/>
<field name="view" class="java.lang.String"/>
<group name="user">
<groupExpression><![CDATA[$F{username}]]></groupExpression>
</group>
<columnHeader>
<band height="20">
<staticText>
<reportElement uuid="6cb3e793-d932-4d29-aca4-3b1efa03a5dd" x="0" y="0" width="185" height="20"/>
<textElement/>
<text><![CDATA[username]]></text>
</staticText>
<staticText>
<reportElement uuid="341be19e-6a83-4b8d-9878-8e2c8760b014" x="185" y="0" width="185" height="20"/>
<textElement/>
<text><![CDATA[category]]></text>
</staticText>
<staticText>
<reportElement uuid="8778300d-b296-41d9-9d12-abda95a80c71" x="370" y="0" width="185" height="20"/>
<textElement/>
<text><![CDATA[view]]></text>
</staticText>
</band>
</columnHeader>
<detail>
<band height="20" splitType="Stretch">
<textField>
<reportElement uuid="4d88aa40-ee74-4535-99a4-e3aec64188d2" isPrintRepeatedValues="false" x="0" y="0" width="185" height="20"/>
<textElement/>
<textFieldExpression><![CDATA[$F{username}]]></textFieldExpression>
</textField>
<textField>
<reportElement uuid="c098560e-c140-4b9a-9599-ed0875014c0f" x="185" y="0" width="185" height="20"/>
<textElement/>
<textFieldExpression><![CDATA[$F{category}]]></textFieldExpression>
</textField>
<textField>
<reportElement uuid="1784b19e-6adb-4d3e-aa04-d172ee39a7cf" x="370" y="0" width="185" height="20"/>
<textElement/>
<textFieldExpression><![CDATA[$F{view}]]></textFieldExpression>
</textField>
</band>
</detail>
</jasperReport>