How can I check if a variable is defined in Thymeleaf?
Something like this in Javascript:
if (typeof variable !== 'undefined') { }
or this in PHP:
if (isset($var)) { }
Is there an equivalent in Thymeleaf?
解决方案
Yes, you can easily check if given property exists for your document using following code. Note, that you're creating div tag if condition is met:
I wonder, if variable exists...
If you want using variable's field it's worth checking if this field exists as well
I wonder, if variable.name exists...
Or even shorter, without using if statement
I wonder, if variable.name exists...
But using this statement you will end creating div tag whether variable or variable.name exist
You can learn more about conditionals in thymeleaf here