4

I am trying to understand how freemarker evaluates an if statement with multiple conditions for example:

<#if person?? && person.phone?has_content && person.phone != "11">
    do something
</#if>

If person?? returns false will freemarker still evaluate the rest of the statement or will it just return false for the whole statement? I'm trying to figure out if person.phone is null will this if statement throw an error when it tries to evaluate the last condition in the if statement? I was trying make it as clean as possible instead of having to nest a bunch of if statements.

Thanks!

4

1 回答 1

3

在 Java 中,逻辑运算符&&||短路,意味着如果不需要,它们不会在运算符之后评估任何内容。

在您给出的示例中,如果person评估为,false则不会评估其余条件。

这个答案提供了一个很好的例子

此外,此论坛主题的最后一篇文章专门讨论了支持短路逻辑运算符的 freemarker

于 2013-10-25T13:46:02.720 回答