简体   繁体   English

如何在Thymeleaf页面中显示ArrayList对象

[英]How to display ArrayList Object in Thymeleaf page

I try to display Arraylist object in Thmeleaf page but I got null for the value. 我尝试在Thmeleaf页面中显示Arraylist对象,但该值的值为null
I can display the arraylist in controller on console. 我可以在控制台的控制器中显示arraylist。 Is it correct the way I pass arraylist in function. 我在函数中传递arraylist的方式是否正确?

In controller 在控制器中

@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 page HTML页面

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

我通过在模型中添加arraylist解决了这个问题

model.addAttribute("rowTypes2", rowTypes2);

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM