Thymeleaf: Concatenation - Could not parse as expression Thymeleaf: Concatenation - Could not parse as expression java java

Thymeleaf: Concatenation - Could not parse as expression


But from what I see you have quite a simple error in syntax

<p th:text="${bean.field} + '!' + ${bean.field}">Static content</p>

the correct syntax would look like

<p th:text="${bean.field + '!' + bean.field}">Static content</p>

As a matter of fact, the syntax th:text="'static part' + ${bean.field}" is equal to th:text="${'static part' + bean.field}".

Try it out. Even though this is probably kind of useless now after 6 months.


You can concat many kind of expression by sorrounding your simple/complex expression between || characters:

<p th:text="|${bean.field} ! ${bean.field}|">Static content</p>


Note that with | char, you can get a warning with your IDE,for exemple I get warning with the last version of IntelliJ,So the best solution it's to use this syntax:

th:text="${'static_content - ' + you_variable}"