当前位置:   article > 正文

mysql中的has content,??之间的区别,has_content,if_exists存在于freemarker中

mysql中的has content,??之间的区别,has_content,if_exists存在于freemarker中

what is the difference between the following in freemarker?

!

has_content

??

if_exists

I used ?? instead of has_content & it lead to such huge issues. Screwed up my day. I really need to get this thing clarified.

When I used

!(xyz.abc!)?? -- it dint work

When I used

!(xyz.abc!)?has_content ... it did work

Doesn't ?? OR has_content OR if_exists check for the same thing?

解决方案

?? tells if the left hand operand's value is missing (means it's Java null or you have an undefined variable there), and gives back false (missing) or true (not missing) accordingly.

?has_content is very much like ??, except it also returns false for a 0-length string or empty FTL sequence (like java.util.List, Java array, etc.) or empty FTL hash (like java.util.Map, etc.). (It doesn't return false for a 0, boolean false, etc.)

! is used to give a default value when a value is missing (again means that it's Java null or you have an undefined variable), like color!"no color". If you omit the right hand operand of !, then the default value is an empty string and empty sequence and empty hash on the same time (a multi-typed value), which is handy for writing things like , ${foo!}.

?if_exists is the old way of writing ??. Don't use it.

While we are here, note that all these operators only cover the last step of a dotted or [] expression, like user.price!0 only handles if price is missing from user, but not if user itself is missing. To cover both possibilities, use (user.price)!0, which handles all missing variable errors thrown during the evaluation of the (), no mater where they come from.

声明:本文内容由网友自发贡献,不代表【wpsshop博客】立场,版权归原作者所有,本站不承担相应法律责任。如您发现有侵权的内容,请联系我们。转载请注明出处:https://www.wpsshop.cn/w/Cpp五条/article/detail/658277
推荐阅读
相关标签
  

闽ICP备14008679号