2017-08-02 47 views
0

ThraleafページにArraylistオブジェクトを表示しようとしましたが、値がnullになっています。 arraylistをコンソールのコントローラに表示できます。それは私が機能のarraylistを渡す方法が正しいです。コントローラでThymeleafページにArrayListオブジェクトを表示する方法

@RequestMapping("/searchSummon") 
    public String Search(Model model) 
    { 

    model.addAttribute("summonsDetailType", new SummonsDetailType()); 
    model.addAttribute("rowType", new RowType()); 

    return "searchSummon"; 
} 

    @RequestMapping(value = "/searchProcess",method =RequestMethod.POST) 
public String searchProcess(SummonsDetailType summonsDetailType,RowType 
rowType) 
{ 

    ArrayList<RowType> rowTypes2 = new ArrayList<RowType>(); 

    SummonsDetailType summonsDetailType2 = 
    pdxiRes.getRequest().getSummonsDetail(); 
    for(RowType rowType3 : summonsDetailType2.getRow()) 
    { 
     rowTypes2.add(rowType3); 

    } 
    System.out.println(rowTypes2.get(0).getDistrictCode()); 

    return "/searchResult"; 

} 

htmlページ

<tr th:each="rowType : ${rowType}"> 

<td th:text="'NRIC NO: ' + ${rowType.DistrictCode}" ></td> 
</tr> 
+2

をArrayListのを追加することで問題を解決しました。コードは他の方法でも本当に奇妙に見えますが、チュートリアル/ドキュメントでもう少し時間を過ごすことをお勧めします。 – Kayaman

+1

ArrayListを 'Search'メソッドと同じようにモデルに追加します。 –

+0

'model.addAttribute(" rowType "、new RowType());'私はこの行を疑っています。 – soorapadman

答えて

0

私はあなたがモデルにリストを追加したことがないモデルに

model.addAttribute("rowTypes2", rowTypes2); 
関連する問題