(五)Thymeleaf标准表达式之——[7->8]条件表达式& 默认表达式
2017-05-23 11:09
363 查看
2.7 条件表达式
模板名称:condition-express.html
<1>a ? b:c (if then:else)
<2>a?c (if else)
条件表达式(
e.g.
[b]2.8 默认表达式([/b]Elvis operator )
模板名称:condition-express.html
语法: ?: (if:defaultValue)
the first one is used if it doesn’t evaluate to null, but if it does then the second one is used.(值不为null使用第一个,否则第二个)
e.g.
equals:
模板名称:condition-express.html
<1>a ? b:c (if then:else)
<2>a?c (if else)
条件表达式(
condition,
then和
else)的所有三个部分都是表达式,这意味着它们可以是变量(
${...},
*{...}),消息(
#{...}),URL(
@{...})或文字(
'...'))。
e.g.
<li>? 'xx' :'xx'(if ? then:else)<span th:class="${title} ? 'green' :' red'">样例一</span></li> <li>?'xx'(if ? then)<span th:class="${title1} ? 'green'">样例二</span></li>
<!-- 嵌套 --> <tr th:class="${row.even}? (${row.first}? 'first' : 'even') : 'odd'"> ... </tr>
<!-- Else表达式也可以省略,在这种情况下,如果条件为false,则返回null值 --> <tr th:class="${row.even}? 'alt'"> ... </tr>
[b]2.8 默认表达式([/b]Elvis operator )
模板名称:condition-express.html
语法: ?: (if:defaultValue)
the first one is used if it doesn’t evaluate to null, but if it does then the second one is used.(值不为null使用第一个,否则第二个)
e.g.
<div th:object="${session.user}"> ... <p>Age: <span th:text="*{age}?: '(no age specified)'">27</span>.</p> </div>
equals:
<p>Age: <span th:text="*{age != null}? *{age} : '(no age specified)'">27</span>.</p>
相关文章推荐
- (四)Thymeleaf标准表达式之——[3->6] 操作符(文本、算术、布尔、比较及相等)
- Thymeleaf教程 (五) Thymeleaf标准表达式语法(下)
- Thymeleaf教程 (四) Thymeleaf标准表达式语法(上)
- Thymeleaf教程 (五) Thymeleaf标准表达式语法(下)
- 拉姆达表达式 追加 条件判断 Expression<Func<T, bool>>
- Thymeleaf教程 (五) Thymeleaf标准表达式语法(下)
- 无法确定条件表达式的类型,因为“<null>”和“System.DateTime”之间没有隐式转换 解决办法
- //使用条件表达式作为简单的“如果...那么...”判断。 #include <iostream> using namespace std; int main() { int score=2; s
- <Python进阶读书笔记>之(五) 条件表达式
- (三)Thymeleaf标准表达式之——文字(literals)
- Thymeleaf 标准表达式语法
- thymeleaf条件表达式
- 条件表达式-Thymeleaf常见用法(五)
- Android 情景模式->标准->默认通知提示音->第一次开机如何默认选中"无"
- if(cin) while(cin) 以及 while(cin>>x) 条件表达式中的 流对象cin 的用法
- Thymeleaf教程 (七) 条件表达式用法
- 无法确定条件表达式的类型,因为“<null>”和“int”之间没有隐式转换
- 拉姆达表达式 追加 条件判断 Expression<Func<T, bool>>
- 函数-->指定函数--->默认函数--->动态函数--> 动态参数实现字符串格式化-->lambda表达式,简单函数的表示
- (七)Thymeleaf的 th:* 属性之—— th: ->设值& 遍历迭代& 条件判断