using thymeleaf之五条件表达式

来源:互联网 发布:想要女生的身体 知乎 编辑:程序博客网 时间:2024/05/16 14:08

5.条件表达式

5.1 ? 'xx' :'xx'(if ? then:else)

e.g.<span th:class="${title} ? 'green' :' red'">样例一</span>

分析:if语句返回null,即为false,走else语句,即返回red;不为null,即为true,返回green.

5.2 ?'xx'(if ? then)

e.g.<span th:class="${title1} ? 'green'">样例二</span>

5.3 设置默认表达式?:

只有if语句值为null时才会设置为默认表达式

e.g.<span th:class="${title2} ?: 'blue'">样例四</span>




0 0