项目场景:Thymeleaf模板引擎拿数据爆红
例如:Thymeleaf模板引擎在html中拿到后端传来的数据爆红
问题描述
在Controller层向model中塞入的key value形式的数据,在html中使用Thymeleaf模板引擎去拿却爆红
例如:
<form action="" method="post">
<tr th:each="item:${notePageData.list}">
<!--/*@thymesVar id="id" type="com.hgc.iva.bean.Note"*/-->
<td><input type="checkbox" name="ids" th:value="${item.id}"></td>
<td th:text="${item.id}"></td>
<td th:text="${item.noteName}"></td>
<td th:text="${item.noteContent}"></td>
<td th:text="${item.noteTime}"></td>
<td th:text="${item.user.username}"></td>
</tr>
</form>
Controller层:
@RequestMapping("/selectAllNote")
public String selectAllNote(@RequestParam(name = "pageNum", defaultValue = "1") Integer pageNum, Model model) {
PageInfo<Note> notePageInfo = noteService.selectAllNote(pageNum);
model.addAttribute("notePageData", notePageInfo);
return "noteList";
}
原因分析:
如果向model中传递的key 和接受中的复杂类型相同,且正确的点出相应的字段。你可以试试run运行一下。