JasperReport Table組件使用JavaBean作爲數據源

JasperReport Table組件使用JavaBean作爲數據源

首先

Bean中要有對應的List

public class CheckFormBean {
 private String id;
   private String company;
   ...
   private List<TableBean> tableBeanList;
   private List<FixCountTableBean> fixCountTableBeans;
   ...
   }


public class TableBean {
    private String type;
    private String width;
    private  String height;
    ...
}

public class FixCountTableBean {
    private String type;
    private String width;
    private String structureType;
    ...

工廠類

public class BeanFactory {

    public static ArrayList<CheckFormBean> getBeanCollection(){
        ArrayList<CheckFormBean> checkFormBeans=new ArrayList<>();
        ArrayList<TableBean> tableBeans=new ArrayList<>();
        ArrayList<FixCountTableBean> fixCountTableBeans=new ArrayList<>();


        CheckFormBean checkFormBean=new CheckFormBean("13","11","13","41","15",....);
        tableBeans.add(new TableBean("挖洞","20","20","400","100","50","500"));
       	...
        fixCountTableBeans.add(new FixCountTableBean("修路",....));
        ...


        checkFormBean.setFixCountTableBeans(fixCountTableBeans);
        checkFormBean.setTableBeanList(tableBeans);
        checkFormBeans.add(checkFormBean);



        return checkFormBeans;
    }

}


在模版中
添加Table組件
並且新建數據源
在Source頁面下找到DatasetRun標籤修改爲

<datasetRun subDataset="Dataset2" uuid="6f80b566-fa9a-45ca-98db-a640206367c7">
						<datasetParameter name="p1">
							<datasetParameterExpression><![CDATA[new net.sf.jasperreports.engine.data.JRBeanCollectionDataSource( $F{tableBeanList})]]></datasetParameterExpression>
						</datasetParameter>
						<dataSourceExpression><![CDATA[new net.sf.jasperreports.engine.data.JRBeanCollectionDataSource( $F{tableBeanList})]]></dataSourceExpression>
					</datasetRun>

其中Dataset2爲Table數據源

發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章