
例如,您有一对JavaBean(POJO):
public class Order { private double price; private int quantity; private Product product; // public getters }public class Product { private String name; // public getters }并且您以这种方式声明报告的数据源:(是的,我喜欢 Guava )
JRBeanCollectionDataSource datasource = new JRBeanCollectionDataSource(Lists.newArrayList(ImmutableList.<Order>builder() .add(new Order(1000.2, 10, new Product("Phone"))) .add(new Order(10200.0, 2, new Product("Tv"))) .build()));如果使用此字段声明:
<field name="order" > <fieldDescription><![CDATA[_THIS]]></fieldDescription></field><field name="price" /><field name="quantity" /><field name="productName" > <fieldDescription><![CDATA[product.name]]></fieldDescription></field>
您可以使用以下表达式:
<textField> <reportElement x="0" y="0" width="100" height="30"/> <textFieldexpression><![CDATA[$F{price}]]></textFieldexpression></textField><textField> <reportElement x="100" y="0" width="100" height="30"/> <textFieldexpression><![CDATA[$F{quantity}]]></textFieldexpression></textField><textField> <reportElement x="200" y="0" width="100" height="30"/> <textFieldexpression><![CDATA[$F{productName}]]></textFieldexpression></textField>注意:
- 不要忘记吸气剂应该是公开的
- 更多信息:JavaBean数据源
欢迎分享,转载请注明来源:内存溢出
微信扫一扫
支付宝扫一扫
评论列表(0条)