表达式语言不是三元的条件语句
conditional statement with expression language that is not ternary
我需要制作一个表达式语言条件语句,其中包含一些要检查的条件。谷歌搜索我只能找到使用三元
的例子
#{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.
}
如何用表达式语言写这个?
与普通 Java.
中的语法相同
#{bean.property eq 'a' ? 'Ant' : bean.property eq 'b' ? 'Bob' : bean.property eq 'c' ? 'C++' : null}
请注意,property
被假定为 String
或 enum
而不是 char
,因为 char
的解释方式与中的数字相同EL。另见 How to compare a char property in EL。
我需要制作一个表达式语言条件语句,其中包含一些要检查的条件。谷歌搜索我只能找到使用三元
的例子#{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.
}
如何用表达式语言写这个?
与普通 Java.
中的语法相同#{bean.property eq 'a' ? 'Ant' : bean.property eq 'b' ? 'Bob' : bean.property eq 'c' ? 'C++' : null}
请注意,property
被假定为 String
或 enum
而不是 char
,因为 char
的解释方式与中的数字相同EL。另见 How to compare a char property in EL。