不能直接使用,需要用转义符替代。
(但是我试了一下 > 可以直接用,< 直接使用会报错。不知道为啥,谁知道原因告诉我一下)
Values in expressions can be compared with the >
, <
, >=
and <=
symbols, and the ==
and !=
operators can be used to check for equality (or the lack of it). Note that XML establishes that the <
and >
symbols should not be used in attribute values, and so they should be substituted by <
and >
.
<div th:if="${prodStat.count} > 1">
<span th:text="'Execution mode is ' + ( (${execMode} == 'dev')? 'Development' : 'Production')">
A simpler alternative may be using textual aliases that exist for some of these operators: gt
(>
), lt
(<
), ge
(>=
), le
(<=
), not
(!
). Also eq
(==
), neq
/ne
(!=
).
在表达式中的值可以与进行>, <, >=, <= 等符号的比较,也可以使用 ==, !=, 进行是否相等的判断。
但是要注意 xml建立的符号(在xml 有特殊意义的符号) < ,和 > 不能用在属性值中,应该被替代为 < 和 > 。
还有一个简单的替代方案,就是可以使用文本别名。
gt
(>
),lt
(<
),ge
(>=
),le
(<=
),not
(!
), eq
(==
),neq
/ ne
(!=
)。
2017/11/29 更新 关于>为什么可以直接使用的原因:
来自!http://blog.sina.com.cn/s/blog_6707d8b301011ht7.html
实体引用
在 XML 中,一些字符拥有特殊的意义。
如果你把字符 "<" 放在 XML 元素中,会发生错误,这是因为解析器会把它当作新元素的开始。
这样会产生 XML 错误:
<message>if salary < 1000 then</message>
为了避免这个错误,请用实体引用来代替 "<" 字符:
<message>if salary <
1000 then</message>
在 XML 中,有 5 个预定义的实体引用:
< | < | 小于 |
> | > | 大于 |
& | & | 和号 |
' | ' | 单引号 |
" | " | 引号 |
注释:在 XML 中,只有字符 "<" 和 "&" 确实是非法的。大于号是合法的,但是用实体引用来代替它是一个好习惯。