我如何在百里香中显示对象

时间:2018-06-27 02:22:25

标签: java spring spring-mvc thymeleaf

我需要显示我从控制器获得的用户列表。

@GetMapping("/maintenance-user")
public ModelAndView Index() throws Exception
{
    ModelAndView model = new ModelAndView("maintenance/user/index");
    model.addObject("model",service.get());

    return model;
}

service.get返回一个Iterable对象

这是我的观点

<p th:text="${model.Id}"></p>

但它返回属性或在对象上找不到字段'Id'。

我在这里想念什么?

1 个答案:

答案 0 :(得分:0)

您需要使用类似于下面的th:each来迭代列表

<tr th:each="obj : ${model}">
     <td th:text="${obj.Id}">Onions</td>
</tr>