Freemarker the processing of null values is very strict, freemarker variables must have values, not assigned to the variable will throw an exception, because Freemarker unassigned variable coercion error can eliminate many potential errors, such as missing potential variable name, or other variable error. The null value mentioned here actually includes those variables that do not exist, and for a null value of Java, we think that this variable exists, except that its value is null, but for the freemarker template it cannot understand the null value. Null values are exactly the same as non-existent variables.
To handle missing variables, Freemarker provides two operators:
!: Specify default values for missing variables
??: Determine if a variable exists
Of these, there are two ways to use operators:
variable! or Variable!defaultvalue, the first usage does not specify a default value for the missing variable, indicating that the default value is an empty string, a collection of length 0, or a map object with a length of 0.
Use! When you specify a default value, the default value is not required to be of the same type and variable type. Use?? The operator is very simple and always returns a Boolean value, using: Variable??, If the variable exists, returns True, otherwise false
Freemarker NULL processing operator