I have part of the 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";
}
where I try to addAttribute List<Question> to be passed on to thymeleaf page. But on the thymeleaf side I only get the "cannot resolve" error.
Part of the .html in showSurvey.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>
Packaging with mvn package and then running the jar starts up the application, and it works, but crashes when trying to resolve "survey" on showSurvey.html so SurveyDAO.GetSurveyById(id);
actually comes back properly.
So how should I go about passing the list and then showing proper values out of it? It has two int and String for all that matters.
You are missing a right "}" - I have just tested this, and it works fine:
<table>
<tr th:each="survey : ${survey}">
<td th:text="${survey}">1</td>
</tr>
</table>
Just a typo.
Like I said in the comments your code doesn't look right.
Fix your code like so:
<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>
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.