Should I choose == or eq for comparing string in EL?

前端 未结 3 1047
不知归路
不知归路 2020-12-24 11:10

== and eq give the same result using EL to do my string comparison tests:

    

        
3条回答
  •  天涯浪人
    2020-12-24 11:39

    According to documentation, it's the same thing

    In addition to the . and [] operators discussed in Value and Method Expressions, the EL provides the following operators, which can be used in rvalue expressions only:
    [...]
    Relational: ==, eq, !=, ne, <, lt, >, gt, <=, ge, >=, le. Comparisons can be made against other values or against Boolean, string, integer, or floating-point literals.

    One difference though : string operators like eq, ne, lt, gt, ge, le exist as they are XML safe, they would not need to be escaped like <= for instance.

    It's explained here

    A useful feature of the EL is the ability to perform comparisons, either between numbers or objects. This feature is used primarily for the values of custom tag attributes, but can equally be used to write out the result of a comparison (true or false) to the JSP page. The EL provides the following comparison operators:

    • == or eq
    • != or ne
    • < or lt
    • > or gt
    • <= or le
    • >= or ge

    The second version of each operator exists to avoid having to use entity references in JSP XML syntax; however, the behavior of the operators is the same.

提交回复
热议问题