Before adding any other fields to Planets
, go to PlanetController
and update the index handler to pass in a Model
class argument (eg. Model model
).
@GetMapping()
public String displayIndex(Model model) {
model.addAttribute("planets", Planets.values());
return "index";
}
In templates/index
, create a list element and use the template
variable you have just defined in the controller to list all of the
planet values on the page.
<ol>
<li th:each="planet : ${planets}" th:text="${planet}"></li>
</ol>
Update the template to display the planet names.
<ol>
<li th:each="planet : ${planets}" th:text="${planet.name}"></li>
</ol>
Change the index template to display a table of each planet name and its year in earth days.
templates/index
, create a table element and add the appropriate bootstrap class.yearLength
field.1 2 3 4 5 6 7 8 9 10 11 | <table th:each="planet : ${planets}" class="table table-striped">
<thead >
<tr>
<th th:text="${planet.name}">
</th>
</tr>
</thead>
<tr>
<td th:text="${planet.yearLength} + ' Earth days in one year.'"></td>
</tr>
</table>
|