Home > Web Front-end > JS Tutorial > Freemarker method to determine whether an object is empty_javascript skills

Freemarker method to determine whether an object is empty_javascript skills

WBOY
Release: 2016-05-16 15:45:14
Original
1368 people have browsed it

FreeMarker has nothing to do with web containers, that is, it does not know about Servlets or HTTP when running on the web. It can not only be used as an implementation technology for the presentation layer, but can also be used to generate XML, JSP or Java, etc.

To display an object in freemarker, use ${name}.

But if name is null, freemarker will report an error. If you need to determine whether the object is empty:

<#if name&#63;&#63;>
……
</#if>
Copy after login

Of course, you can also avoid the error of the object being empty by setting the default value ${name!''}. If name is empty, the default value (characters after "!") will be displayed.

If the object user and name are attributes of user, both user and name may be empty, then it can be written as ${(user.name)!''}, which means that user or name is null, both will be displayed as empty.

Judged to be empty

<#if (user.name)&#63;&#63;>
……
</#if>
Copy after login

Method 2:

For null or miss value, freemarker will report an error

!: default value operator, the syntax structure is: unsafe_expr!default_expr, such as ${mouse!"No mouse."} When mouse does not exist, return default value;

(product.color)!"red" This method can handle the situation where product or color is a miss value;

And product.color!"red" will only handle the case where color is miss value

??: Missing value test operator, tests whether it is missing value

unsafe_expr??: product.color?? will only test if color is null

(unsafe_expr)??: (product.color)?? will test whether product and color are null

?exists:Usage of old version

For example:

<#if mouse&#63;&#63;>
 Mouse found
<#else>
 No mouse found
</#if>
Creating mouse...
<#assign mouse = "Jerry">
<#if mouse&#63;&#63;>
 Mouse found
<#else>
 No mouse found
</#if>
Copy after login

The above uses two methods to introduce the method of freemarker to determine whether an object is empty. I hope you like it.

source:php.cn
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template