Answer the question
In order to leave comments, you need to log in
Themeleaf: How to display a default message on a page?
Good evening!
Such a question, when the model is displayed on the html page, and there is no data, I would like what would be written in the tag - "no data" can this be done on the page itself without resorting to adding an attribute in the controller?
Example:
<span th:text="'Your city : ' + ${address.city}">Non data</span>
Answer the question
In order to leave comments, you need to log in
Hello!
Why don't you use the capabilities of the template engine?
Here are a few options for solving the issue:
1) Using the ternary operator
<span th:text="${address.city != null} ? ${address.city} : 'No data!'">City</span>
==
, and if it's an object, then you need to useeq
<span th:if="${address.city} == null">Non data</span>
<span th:unless="${address.city} != null" th:text="'Your city : ' + ${address.city}">Non data</span>
?.
between address & city<span th:text="'Your city : ' + ${address?.city}">Non data</span>
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question