我正在使用Freemarker 2.3.23生成报告。 以下是我使用的类的def:
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;
}
}
我使用下面的模板打印表格中单元格中的每个元素。但是没有输出生成的报告是空的html: 我尝试了2层嵌套类,但它工作但不是这种情况。
<#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>
答案 0 :(得分:0)
以上代码应该有效。它不起作用的原因是由于对上述代码中未列出的字段的错误分配。