刚开始学ireport是使用sql作为数据源,因为直接sql是最简单也最容易上手的,但是sql已经无法满足现在的业务需求了,于是乎寻找其他的解决方案,于是乎找到了JRDataSource数据源。个人觉得sql数据源最简单,其次就是JRDataSource数据源了。
一、使用JRDataSource数据源首先要实现 JRRewindableDataSource 接口
/**
* @Author: BlueSky
* @CreateTime: 2020-01-06 13:50
* @Description:
*/
import java.util.List;
import net.sf.jasperreports.engine.JRException;
import net.sf.jasperreports.engine.JRField;
import net.sf.jasperreports.engine.JRRewindableDataSource;
public class GenericDataSource implements JRRewindableDataSource{
int index;
List<PrintRecord> records;
public GenericDataSource(List<PrintRecord> records) {
this.records = records;
this.index = -1;
}
@Override
public Object getFieldValue(JRField jrField) throws JRException {
String fieldName = jrField.getName();
return records.get