Thymeleaf Expressions

Get introduced to the usage of Thymeleaf expressions.

We just introduced the Thymeleaf expressions (enclosed within th:* tags). These can be classified into six categories:

  1. Variables
  2. Text
  3. Selected objects
  4. Links
  5. Literal substitutions
  6. Expression inlining

Variables

When a Thymeleaf template gets processed, the application will put variables in the context via the controller. We can reference those variables in the templates via the ${…} syntax. For example:

<div th:text="${username}"></div>

Suppose there is a String in the Thymeleaf context with the name username that has the value “John Doe.” The HTML will be rendered as: ...