【问题标题】:conditional statement with expression language that is not ternary非三元表达式语言的条件语句
【发布时间】:2016-10-05 17:31:17
【问题描述】:

我需要用一些条件来检查表达式语言条件语句。谷歌搜索我只能找到使用三元的例子

#{SomeBean.someProperty ? 'bob' : 'John'}

不过我需要更多条件。我需要类似的东西:

If (SomeBean.someProperty == 'a'){
   //Ant
}
Else if (SomeBean.someProperty == 'b'){
   //Bob
}
Else if (SomeBean.someProperty == 'c'){
   //C++
}
Else{
   //Back to the drawing board, something went wrong.
}

如何用表达式语言写这个?

【问题讨论】:

    标签: el


    【解决方案1】:

    与普通 Java 中的语法相同。

    #{bean.property eq 'a' ? 'Ant' : bean.property eq 'b' ? 'Bob' : bean.property eq 'c' ? 'C++' : null}
    

    请注意property 被假定为Stringenum 而不是char,因为char 的解释方式与EL 中的数字相同。另见How to compare a char property in EL

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2016-12-18
      • 1970-01-01
      • 1970-01-01
      • 2012-08-06
      • 2014-11-06
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多