急问!用JasperReport生产PDF。模板都正确,文件也生成了。但是文件一共有两行内容,第一行是“John”的信息,第二行是“Kelly”的信息。用了List
import java.io.FileInputStream;
import java.io.FileOutputStream;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
import net.sf.jasperreports.engine.JasperExportManager;
import net.sf.jasperreports.engine.JasperFillManager;
import net.sf.jasperreports.engine.JasperPrint;
import net.sf.jasperreports.engine.data.JRBeanCollectionDataSource;
public class createPDF {
public static void main(String[] args) throws Exception {
String filePath = "........Scorecard_Summary.jasper"; //此处省略我的文件链接
FileInputStream inputStream = new FileInputStream(filePath);
//需要打印的信息 (共两行内容,行标题为:driverID,year,month...idleScore)
String[] driverID = {"John", "Kelly"};
String[] year = {"2022", "2023"};
String[] month = {"2022", "2023"};
String[] macroScore = {"2022", "2023"};
String[] milesScore = {"2022", "2023"};
String[] speedScore = {"2022", "2023"};
String[] mpgScore = {"2022", "2023"};
String[] idleScore = {"2022", "2023"};
Map<String,Object> params = null;
List
这里运行完成以后,List里保存了以下信息:
{mpgScore=2022, driverID=John, month=2022, speedScore=2022, year=2022, milesScore=2022, macroScore=2022, idleScore=2022}
{mpgScore=2023, driverID=Kelly, month=2023, speedScore=2023, year=2023, milesScore=2023, macroScore=2023, idleScore=2023}
*/
JRBeanCollectionDataSource ds = new JRBeanCollectionDataSource(list);
JasperPrint jasperPrint = JasperFillManager.fillReport(inputStream,params,ds);
JasperExportManager.exportReportToPdfStream(jasperPrint, new FileOutputStream("........\\summary.pdf")); //此处省略输入PDF地址
}
}
文件是生成了,但是两行文本内容都是“Kelly”(也就是最后一条内容)
生产文件,第一行内容为“John”,第二行内容为“Kelly”的,谢谢!
那就再分别看这些参数跟方法,看是哪里覆盖了
发一下模板