When using freemaker template to get values, an error is reported when the attribute is empty

When the expression ${(user. Name)! “} in freemaker is empty, an error is reported directly

FreeMarker is a template engine written in Java language. It generates text output based on the template and uses FreeMarker to judge whether the object is empty.

    general data is judged at the back end, and the front end only displays it regardless of logic. Freemaker displays that an object uses ${name}.
    but if the name is null, freemaker will report an error. If you need to judge whether the object is empty: & lt; #if name?& gt;… & lt;/#if & gt;. You can also set the default value ${name! “”} To avoid the error that the object is empty. If the name is empty, it will be displayed with the default value (the character after “!”). The object user and name are the attributes of user. At this time, both user and name may be empty, which can be written as ${(user. Name)! “”}, indicating that user or name is null, which will be displayed as empty.


Read More: