我有 Controller 的一部分:
@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";
}
我尝试将 addAttribute List
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 来处理所有重要的事情。
最佳答案
你错过了一个正确的“}” - 我刚刚测试过这个,它工作正常:
<table>
<tr th:each="survey : ${survey}">
<td th:text="${survey}">1</td>
</tr>
</table>
只是一个错字。
关于java - 使用 Spring 引导将 list<object> 传递给 thymeleaf,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/44225978/