代码之家  ›  专栏  ›  技术社区  ›  Vaishak Suresh

将JavaBean的集合作为数据源传递给蟑螂合唱团,如何在IWReans中设计它

  •  1
  • Vaishak Suresh  · 技术社区  · 14 年前

    我需要设计一个报告,显示一个集合(比如列表)中的数据。此列表包含多个POJO。

    POJO由应用程序的数据访问层填充。如何在iReports中为此需求设计报表模板?

    3 回复  |  直到 9 年前
        1
  •  1
  •   Bozho    14 年前

    使用 JRBeanCollectionDataSource 为了你的报告。

        2
  •  1
  •   Vaishak Suresh    14 年前

    好啊!找到了答案。步骤如下。

    1. 编译bean类并创建JAR文件。这需要完整的包裹
    2. 将此jar添加到iReports中的lib文件夹
    3. 创建一个工厂/包装类,该类具有用于填充集合的CreateBeanCollection方法
    4. 将此类的顶级包用作IReports中的类路径
    5. 使用该类作为方法的JavaBean数据源。

    一旦完成这一切,用新的数据源和报表查询创建报表,在JavaBean上给出FQN并添加所需的字段。

        3
  •  0
  •   Najera Dark Army    9 年前
    BankDetailsList list = new BankDetailsList();       
    ArrayList<BankDetails> lst = list.getDataBeanList();        
    JRBeanCollectionDataSource beanColDataSource = new JRBeanCollectionDataSource(lst);
    

    这是银行资料。

    public class BankDetails {
    
        public String bank_name;
        public Account account;
        public String custodian_account;
        public String custodian_name;
        public String agreement_type;
        public double exposure;
        public double collateral;
        public double independant_amount;
            public double net_exposure;
    
        BankDetails(String b_name, Account acc, String cust_account,
            String cust_name, String agr_type, double expo, double collat,
            double independant_amt, double net_exp) {
    
            this.bank_name = b_name;
            this.account = acc;
            this.custodian_account = cust_account;
            this.custodian_name = cust_name;
            this.agreement_type = agr_type;
            this.exposure = expo;
            this.collateral = collat;
            this.independant_amount = independant_amt;
            this.net_exposure = net_exp;
        }
    
        public String getBank_name() {
            return bank_name;
        }
        public void setBank_name(String bank_name) {
            this.bank_name = bank_name;
        }
        public Account getAccount() {
            return account;
        }
        public void setAccount(Account account) {
            this.account = account;
        }
        public String getCustodian_account() {
            return custodian_account;
        }
        public void setCustodian_account(String custodian_account) {
            this.custodian_account = custodian_account;
        }
        public String getCustodian_name() {
            return custodian_name;
        }
        public void setCustodian_name(String custodian_name) {
            this.custodian_name = custodian_name;
        }
        public String getAgreement_type() {
            return agreement_type;
        }
        public void setAgreement_type(String agreement_type) {
            this.agreement_type = agreement_type;
        }
        public double getExposure() {
            return exposure;
        }
        public void setExposure(double exposure) {
            this.exposure = exposure;
        }
        public double getCollateral() {
            return collateral;
        }
        public void setCollateral(double collateral) {
            this.collateral = collateral;
        }
        public double getIndependant_amount() {
            return independant_amount;
        }
        public void setIndependant_amount(double independant_amount) {
            this.independant_amount = independant_amount;
        }
        public double getNet_exposure() {
            return net_exposure;
        }
        public void setNet_exposure(double net_exposure) {
            this.net_exposure = net_exposure;
        }
    }
    

    帐户POJO:

    public class Account {
    
        public int account_id;
        public String account_name;
    
        Account(int acc_id, String acc_name){
            this.account_id = acc_id;
            this.account_name = acc_name;
        }
    
        public int getAccount_id() {
            return account_id;
        }
    
        public void setAccount_id(int account_id) {
            this.account_id = account_id;
        }
    
        public String getAccount_name() {
            return account_name;
        }
    
        public void setAccount_name(String account_name) {
            this.account_name = account_name;
        }
    }