Thymeleaf expression syntax¶
Thymeleaf expression syntax refers to the specific set of symbols and operators used to integrate dynamic content within HTML templates. These expressions allow the engine to process variables, internationalization messages, URLs, and template fragments.
Expression Objects¶
Standard variable expressions are defined using the ${...} syntax, which conforms to the OGCL (Object-Graph Navigation Language) standard.^[600-developer__java__spring__thymeleaf__spring-thymeleaf-01.md] This syntax is typically used for accessing model attributes or bean properties.
A specialized variation is the selection expression, denoted by *{...}^[600-developer__java__spring__thymeleaf__spring-thymeleaf-01.md]. This is often used in conjunction with an object, such as *{object.xxx}, to select properties from a specific object context rather than the entire context map.
Utility Expressions¶
Internationalization¶
Message externalization and internationalization are handled using the #{...} syntax.^[600-developer__java__spring__thymeleaf__spring-thymeleaf-01.md] This allows templates to resolve locale-specific messages from resource bundles.
URLs¶
To link to resources or construct URLs, the @{...} syntax is used^[600-developer__java__spring__thymeleaf__spring-thymeleaf-01.md]. This handles URL rewriting and context path appending automatically.
Fragments¶
Fragment expressions, represented by ~{...}, are used to reference and insert fragments of other templates or markup within the current template^[600-developer__java__spring__thymeleaf__spring-thymeleaf-01.md]. This enables template composition and reusable layout components.
Attributes¶
Thymeleaf allows for the modification of standard HTML attributes. The processor th:id can be used to replace or set the standard HTML id attribute^[600-developer__java__spring__thymeleaf__spring-thymeleaf-01.md].