The aim is to display text on the screen based on certain conditions. The steps for completion are as follows:
- Open the welcome page from the previous sub-section.
- Add the following code above the list at the location marked with the <div>:
<!-- Insert conditional here -->
<div th:if="${#lists.isEmpty(blogPosts)}" class="alert
alert-primary">
There are no blog posts
</div>
- Open a terminal and go to the exercise-basic-thymeleaf folder.
- Enter mvnw spring-boot:run to start the application.
- Navigate your browser to http://localhost:8080 to see the list in action.
- Click the Remove all button to clear the list of blog posts:
With this sub-section, you have displayed the text data on the website based on the applied conditions.
You have seen multiple ways to add attributes to the model. Model attributes can be any arbitrary object that is referenced by a name. The name is defined by the developer when it is added to the model. This can either be in a separate or in a mapping - handling method.