【发布时间】:2017-10-28 18:54:56
【问题描述】:
我有部分控制器:
@RequestMapping(value = "1", method = RequestMethod.GET)
public String greeting(@RequestParam(value="1", required = false, defaultValue = "1") int id, Model model){
List<Question> survey = surveyDAO.getSurveyById(id);
model.addAttribute("survey", survey);
return "showSurvey";
}
我尝试在其中添加属性列表
showSurvey.html 中的部分 .html
<div class="col-sm-12">
<table class="table table-hover">
<tr th:each="survey: ${survey}">
<td th:text="${survey">1</td>
<!-- <td><a href="#" th:text="${message.name}">Title ...</a></td>-->
</tr>
</table>
</div>
使用 mvn package 打包然后运行 jar 会启动应用程序,它可以工作,但在尝试解决 showSurvey.html 上的“调查”时崩溃,因此 SurveyDAO.GetSurveyById(id); 实际上会正常返回。
那么我应该如何传递列表然后从中显示正确的值?它有两个 int 和 String 。
【问题讨论】:
-
<td th:text="${survey">1</td>看起来不对。它必须是这样的<td th:text="${survey.id}">1</td>。 -
哦,是的,你是对的!虽然我只是把它拿出来尝试只使用对象,但结果是一样的,thymeleaf 根本无法解析传入的列表。
-
请同时发布堆栈跟踪。
-
是的,你是对的。原来这只是一个错字...
标签: java spring maven spring-boot thymeleaf