How to use Thymeleaf when the value is null with JavaScript?

Spread the love

Sometimes, we want to use Thymeleaf when the value is null with JavaScript.

In this article, we’ll look at how to use Thymeleaf when the value is null with JavaScript.

How to use Thymeleaf when the value is null with JavaScript?

To use Thymeleaf when the value is null with JavaScript, we use the ? operator.

For instance, we write

<td th:text="${user?.address?.city}"></td>

to set the th:text attribute to the user?.address?.city, which returns undefined if user or address is null or undefined.

Conclusion

To use Thymeleaf when the value is null with JavaScript, we use the ? operator.

Leave a Reply

Your email address will not be published. Required fields are marked *