无法使用 ArrayList 从嵌套 class 打印值
Cannot print value from nested class with ArrayList
我正在使用 Freemarker 2.3.23 生成报告。
以下是我使用的 class 的定义:
public class result{
public ArrayList<Table> expected;
public ArrayList<Table> actual;
public ArrayList<Table> result;
public ArrayList<Stat> stat_list;
public result(){
expected=new ArrayList<Table>();
actual=new ArrayList<Table>();
result=new ArrayList<Table>();
stat_list=new ArrayList<Stat>();
}
public ArrayList<Table> getexpected(){
return expected;
}
public ArrayList<Table> getactual(){
return actual;
}
public ArrayList<Table> getresult(){
return result;
}
public ArrayList<Stat> getstat_list(){
return stat_list;
}
}
public class Table{
public ArrayList<Row> contents;//First row in the table would be for the header.
public HashMap<String,Integer> Col_Index_Map;//Column Header->Column Index Mapping
public Table(){
contents=new ArrayList<Row>();
Col_Index_Map=new HashMap<String,Integer>();
}
public ArrayList<Row> getcontents(){
return contents;
}
public HashMap<String,Integer> getCol_Index_Map(){
return Col_Index_Map;
}
}
public class Row {
public ArrayList<Cell> fields;
public int rowNo;
public Row(){
fields=new ArrayList<Cell>();
rowNo=0;
}
public ArrayList<Cell> getfields(){
return fields;
}
public int getrowNo(){
return rowNo;
}
}
public class Cell {
public ArrayList<String> data;
public Cell(){
data=new ArrayList<String>();
}
public ArrayList<String> getdata(){
return data;
}
}
我使用下面的模板打印 table 中单元格中的每个元素。但是根本没有输出生成的报告是空的html:
我尝试嵌套 2 层 class,它可以工作,但不是这种情况。
<#list expected as expected_table>
<h2>Result Table:</h2>
<table class='table table-bordered reportStyle'>
<td>
<#list expected_table.contents as expected_row>
<tr>
<#list expected_row.fields as expected_cell>
<#list expected_cell.data as expected_item>
${expected_item}
</#list>
</#list>
</tr>
</#list>
</td>
</table>
</#list>
以上代码应该可以工作。它不起作用的原因是对上面代码中未列出的字段的错误分配。
我正在使用 Freemarker 2.3.23 生成报告。 以下是我使用的 class 的定义:
public class result{
public ArrayList<Table> expected;
public ArrayList<Table> actual;
public ArrayList<Table> result;
public ArrayList<Stat> stat_list;
public result(){
expected=new ArrayList<Table>();
actual=new ArrayList<Table>();
result=new ArrayList<Table>();
stat_list=new ArrayList<Stat>();
}
public ArrayList<Table> getexpected(){
return expected;
}
public ArrayList<Table> getactual(){
return actual;
}
public ArrayList<Table> getresult(){
return result;
}
public ArrayList<Stat> getstat_list(){
return stat_list;
}
}
public class Table{
public ArrayList<Row> contents;//First row in the table would be for the header.
public HashMap<String,Integer> Col_Index_Map;//Column Header->Column Index Mapping
public Table(){
contents=new ArrayList<Row>();
Col_Index_Map=new HashMap<String,Integer>();
}
public ArrayList<Row> getcontents(){
return contents;
}
public HashMap<String,Integer> getCol_Index_Map(){
return Col_Index_Map;
}
}
public class Row {
public ArrayList<Cell> fields;
public int rowNo;
public Row(){
fields=new ArrayList<Cell>();
rowNo=0;
}
public ArrayList<Cell> getfields(){
return fields;
}
public int getrowNo(){
return rowNo;
}
}
public class Cell {
public ArrayList<String> data;
public Cell(){
data=new ArrayList<String>();
}
public ArrayList<String> getdata(){
return data;
}
}
我使用下面的模板打印 table 中单元格中的每个元素。但是根本没有输出生成的报告是空的html: 我尝试嵌套 2 层 class,它可以工作,但不是这种情况。
<#list expected as expected_table>
<h2>Result Table:</h2>
<table class='table table-bordered reportStyle'>
<td>
<#list expected_table.contents as expected_row>
<tr>
<#list expected_row.fields as expected_cell>
<#list expected_cell.data as expected_item>
${expected_item}
</#list>
</#list>
</tr>
</#list>
</td>
</table>
</#list>
以上代码应该可以工作。它不起作用的原因是对上面代码中未列出的字段的错误分配。