有 Java 编程相关的问题?

你可以在下面搜索框中键入要查询的问题!

java比较数据源中的行以打印特定记录

主报表使用一个数据源,其中包含一个列表(parentList)。 此列表(父列表)中依次包含其他列表(子列表)。 此子列表作为数据源(JRBeanCollectionDataSource)传递给子报表

子列表包含两列,下面是列表的表格格式

<pre>TestString  | Date</pre>
<pre> abc | 01JAN12 </pre>
<pre> cdf | 31DEC12 </pre>
<pre> fgh | 08JUN12 </pre>

从上表中,应比较日期,以获得记录的“TestString”值,在这种情况下,最新日期(即)cdf

行或记录的比较应该在Jasper报告中完成,而不是在java类中

我该怎么做


共 (1) 个答案

  1. # 1 楼答案

    您必须在java端执行此操作

    假设你有pojo结构

    public class Parent{
        private List<Child> childList;
        ...
    }
    
    public class Child{
        String testString;
        Date date;
    }
    

    在生成报告的java方法中

    ...
    List<Parent> parent = //method for getting datasource
    List<String> testStrings = getTestStrings(parent);
    ...
    //pass the list of testStrings to the report
    //inside the report, create a parameter of type List
    //pass list.get($V{ctr}) to the subreport where ctr is the current count of the subreport, make it start with 0
    

    getTestStrings方法应该执行以下操作

    private List<String> getTestStrings(List<Parent> parent){
        //loop through parent list
        //pull each child list then do the sort by date then get(0).getTestString()
        //put the value in a list
        //return the list
    }