0
我尝试在Thmeleaf页面中显示Arraylist对象,但是我得到的值为null。 我可以在控制台的控制器上显示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>
解决了这个问题你从来没有在列表中添加到模型中。该代码在其他方面看起来也很奇怪,我建议您花更多时间阅读教程/文档。 – Kayaman
将ArrayList添加到模型中,就像您在'Search'方法中做的一样。 –
'model.addAttribute(“rowType”,new RowType())''我怀疑这条线。 – soorapadman