Freemarker NULL processing operator

Source: Internet
Author: User

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

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.