只需对查询进行少量修改即可轻松完成,无需通过多种方式进行编程。
解决方案 1. 在详细信息区域中使用带有条形码组件的单个报告
您可以使用单个报告的模板来生成多个条形码one report.
在这种情况下请求参数表达式(适用于OracleDB)将是这样的:
SELECT seq_barcode.nextval AS barcode, rownum FROM dual CONNECT BY LEVEL <= $P{quantity}
- 它会根据您需要的次数从序列中生成一个值。这$P{数量}参数确定要生成的行数(条形码)。
工作中rjxml file:
<jasperReport ...>
<parameter name="quantity" class="java.lang.Integer">
<defaultValueExpression><![CDATA[20]]></defaultValueExpression>
</parameter>
<queryString>
<![CDATA[SELECT seq_barcode.nextval AS barcode, rownum FROM dual CONNECT BY LEVEL <= $P{quantity}]]>
</queryString>
<field name="BARCODE" class="java.lang.Integer"/>
<field name="ROWNUM" class="java.lang.Integer"/>
<title>
<band height="82" splitType="Stretch">
<textField>
<reportElement x="145" y="18" width="240" height="20"/>
<textElement/>
<textFieldExpression><![CDATA["The number of barcodes is: " + $P{quantity}]]></textFieldExpression>
</textField>
</band>
</title>
<detail>
<band height="47" splitType="Stretch">
<componentElement>
<reportElement x="145" y="10" width="200" height="28"/>
<jr:barbecue xmlns:jr="http://jasperreports.sourceforge.net/jasperreports/components" xsi:schemaLocation="http://jasperreports.sourceforge.net/jasperreports/components http://jasperreports.sourceforge.net/xsd/components.xsd" type="2of7" drawText="false" checksumRequired="false">
<jr:codeExpression><![CDATA[$F{BARCODE}]]></jr:codeExpression>
</jr:barbecue>
</componentElement>
</band>
</detail>
</jasperReport>
结果将是($P{数量} == 5):
在你的情况下请求参数表达式将是这样的:
SELECT to_char(PALLET_ID_NO_SEQ.nextval) AS barcode, rownum FROM dual CONNECT BY LEVEL <= $P{quantity}
和表达Barcode组件将是:
new com.pepkorit.BarbecueRotateRenderer(
net.sourceforge.barbecue.BarcodeFactory.createCode128C($F{barcode}),
false, true, 1, 50, 190, 50)
解决方案 2. 使用组标头带
您可以使用相同的请求参数表达式如第一个解决方案中所示。该小组于rownum字段将帮助我们生成single报告包含属于其自己组的许多条形码(一组 - 一个条形码)。这Barcode组件应放置到组标题 band.
使用是开始新页我们可以管理是否在新页面上生成组的属性。
The rjxml file:
<jasperReport ...>
<parameter name="quantity" class="java.lang.Integer">
<defaultValueExpression><![CDATA[20]]></defaultValueExpression>
</parameter>
<queryString>
<![CDATA[SELECT seq_barcode.nextval AS barcode, rownum FROM dual CONNECT BY LEVEL <= $P{quantity}]]>
</queryString>
<field name="BARCODE" class="java.lang.Integer"/>
<field name="ROWNUM" class="java.lang.Integer"/>
<group name="rownumGroup" isStartNewPage="true">
<groupExpression><![CDATA[$F{ROWNUM}]]></groupExpression>
<groupHeader>
<band height="50">
<componentElement>
<reportElement x="145" y="11" width="200" height="28"/>
<jr:barbecue xmlns:jr="http://jasperreports.sourceforge.net/jasperreports/components" xsi:schemaLocation="http://jasperreports.sourceforge.net/jasperreports/components http://jasperreports.sourceforge.net/xsd/components.xsd" type="2of7" drawText="false" checksumRequired="false">
<jr:codeExpression><![CDATA[$F{BARCODE}]]></jr:codeExpression>
</jr:barbecue>
</componentElement>
</band>
</groupHeader>
</group>
<title>
<band height="82" splitType="Stretch">
<textField>
<reportElement x="145" y="18" width="240" height="20"/>
<textElement/>
<textFieldExpression><![CDATA["The number of barcodes is: " + $P{quantity}]]></textFieldExpression>
</textField>
</band>
</title>
</jasperReport>
In case isStartNewPage=“假”对于团体罗纳姆集团结果将是($P{数量}== 7):
In case isStartNewPage="true"对于团体罗纳姆集团结果将是($P{数量} == 5):
解决方案 3. 使用子报表
我们可以添加子报告组件到Detail band (请参阅第一个解决方案) or 组标题 (请参阅第二个解决方案) 乐队。在这种情况下,您不仅可以将Barcode组件,但你想要的一切。