[英]Passing list<object> to thymeleaf with Spring boot
我有部分控制器:
@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包打包然后运行jar启动应用程序,它可以工作,但在尝试解析showSurvey.html上的“调查”时崩溃所以SurveyDAO.GetSurveyById(id);
实际上回来了。
那么我应该如何通过列表然后显示正确的值呢? 对于所有重要事项,它有两个int和String。
你错过了一个正确的“}” - 我刚试过这个,它运行正常:
<table>
<tr th:each="survey : ${survey}">
<td th:text="${survey}">1</td>
</tr>
</table>
只是一个错字。
就像我在评论中所说,你的代码看起来不正确。
像这样修复你的代码:
<div class="col-sm-12">
<table class="table table-hover">
<tr th:each="survey: ${survey}">
<td th:text="${survey.id}">1</td> // id is a property of the Question class
</tr>
</table>
</div>
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.