主报表传递list到子报表detail方法(JavaBeans set datasource)

javabean
MainReport.java
public class MainReport {
	private List<SubReport> list;

	public List<SubReport> getList() {
		return list;
	}

	public void setList(List<SubReport> list) {
		this.list = list;
	}

SubReport.java
public class SubReport {
	private String data;

	public String getData() {
		return data;
	}

	public void setData(String data) {
		this.data = data;
	}

Factory.java
public class Factory {
	public static Collection<MainReport> createBeanCollection(){
		List<MainReport> ls1 = new ArrayList<MainReport>();
	    List<SubReport> list = new ArrayList<SubReport>();
	    for(int i = 0; i < 4; i++) {
	        SubReport v= new SubReport("data"+i);
	        list.add(v);
	    }
	    MainReport mr = new MainReport(list);
	    ls1.add(mr);
	    return ls1;
	}
}


ireport
设置数据源

主报表设置

生成pdf效果


参考代码与jrxml见附件

你可能感兴趣的:(java)