gpt4 book ai didi

java - jasper report 使用数据源的算法是什么?

转载 作者:行者123 更新时间:2023-11-30 11:59:05 24 4
gpt4 key购买 nike

我已经通过实现接口(interface) JRDataSource 创建了我的自定义数据源。这个界面看起来像这样:

public interface JRDataSource
{
/**
* Tries to position the cursor on the next element in the data source.
* @return true if there is a next record, false otherwise
* @throws JRException if any error occurs while trying to move
* to the next element
*/
public boolean next() throws JRException;

/**
* Gets the field value for the current position.
* @return an object containing the field value. The object type must
* be the field object type.
*/
public Object getFieldValue(JRField jrField) throws JRException;

}

我的问题是:jasper report以什么方式调用这个函数来获取.jrxml中的字段。

例如:

  if( next() )){
call getFieldValue for every field present in the page header
while( next() ){
call getFieldValue for every field present in detail part
}
call getFieldValue for every field present the footer
}

前面只是一个例子,通过实验发现其实不是这样的。所以我的问题出现了。

谢谢!

最佳答案

我实际上认为算法是这样的(简化方式并使用 Java 语法):

while(dataSource.next()) {
for (JRField field : reportFields)
currentValues.put(field, dataSource.getFieldValue(field));
}

字段在 jrxml 文件中的声明与其显示位置无关。

但是,据我所知,默认情况下,每条记录仅生成(绘制或更新)详细信息部分。换句话说,如果您需要更新页面页眉或页脚中的信息,您将不得不做一些花哨的事情。

我相信有一个 evaluationTime 属性可以是 used in several elements这在这方面可能会有所帮助,或者您可能想查看 subreport功能,具体取决于您需要处理的数据量。

就个人而言,我找到了 JasperReports sample projects有帮助,尽管确实需要付出一些努力才能从中获益。我还要指出 The Definitive Guide to JasperReports它的名字是个谎言,但确实是一本不错的(否则完全没有)引用手册。

关于java - jasper report 使用数据源的算法是什么?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/2733317/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com