if - If statement

<if>

If judgment statement

Introduce

Use the Ognl expression to determine if the statement is executed.
Coordinate with <elseif> and <else> tags.

Attribute

test(required)
Using Ognl to judgment the conditions, 
The result is true, then run the code within the if block,
The result is false, not run.

Symbol
==:equal
!=:not equal
&&:and
||:or
trim(optional)
Whether to retain the output value of the front and back blank characters

Property
false:yes(default)
true:no(Including the newline)

Example:

If rule

In test, enter the Ognl expression, the expression return true, if block is executed, if the return is false, skip or enter the next statement soon (such as <elseif> or <else>).

Common judgement symbols

==: equal
!=: not equal
&&: and
||: or
>: greater than
>=: greater than or equal
<: less than
<=: less than or equal
Example: determine the score, 
if it is greater than or equal to 60 points and less than or equal to 100 points, 
then the output: Congratulations, you passed!

Result

Tip: In <if>'s test, the mouse is placed above, or selected, can show the value.

Ognl expression judgment

In <if>'s test, you can judge not only variable, but also Ognl fields or methods of variables.

We initialize a List, which is put into 3 Book objects,
The Book object contain three fields, int:id, String:name, Double:price.

Set the action in the template to IfTagAction for the code prompt

Iterate over all books, and output price, 
when it price is greater than or equal to 50, 
hit 10 percent off, otherwise no discount.

Result

There is a famous saying called "Knowledge makes humble",
however, the following is written as "Knowledge makes proud", and we need to change it.
Determine whether there is prond in String, if it exists, change prond to humble.
In test, you can use the variable's Ognl method to judge.

Result

“==” or “equals(...)”?

In Java, we know that String is equal, need to use the equals method, not ==. But in the Ognl expression, we can also use equals method and ==.

Set a String str, using equals method and ==

We can see the result is the same

trim usage

Trim is to judge whether to retain the output value of the front and back blank characters, the default false, that is to say, output all characters.

The following 2 output methods, one default trim="false", the other trim="true".

As you can see, the first method outputs as it is, 
including front and back spaces and newline characters, 
while the other removes spaces and newline characters.