使用 "1 < 解析 thymeleaf 模板时出错0" [英] Error parsing thymeleaf template with "1 < 0"
问题描述
也许是一个愚蠢的问题,但我未能从谷歌检索信息.正如标题所说,如果尝试解析这个简单的行,我会得到一个堆栈跟踪:
Maybe is a stupid question but I failed to retrieve information from Google. As the title say, I get a stack trace if a try to parse this simple line:
<span th:if="${1 < 0}">
错误是:
org.xml.sax.SAXParseException;行号:14;列数:43;与元素类型null"关联的属性th:if"的值不得包含<"字符.
但是如果我试试这个:
<span th:if="${0 > 1}">
一切都很好,我的问题是:为什么我会收到这个错误?
Everything is fine, my question is: Why I get this error?
我相信这与我缺乏 Java 和 thymeleaf 的经验有关,但我不明白为什么只是改变它按我预期工作的元素的位置(返回始终为 false).
I believe is related to my lack of experience with Java and thymeleaf, but I don't get why by just changing the position of the elements it work as I expect (return always false).
这是表达式解析中的错误(因为某些解析器规则禁止检查 1 是否小于 0)或者只是一个奇怪的 XML 解析问题?
It is a bug in the parsing of the expression (as checking if 1 is lower than 0 is forbidden by some parser rule) or is just a weird XML parsing issue?
感谢所有刚刚阅读的人.
Thank you to all who will even just read.
推荐答案
必须使用
< for <
> for >
≤ for <=
≥ for >=
所以你的代码应该是这样的:
So your code should look like :
<span th:if="${1 < 0}">
您可以在他们的 网站,在比较器和相等部分.
You can find the whole doc about this in the 'Using Thymeleaf' tutorial on their website, in the comparators-and-equality section.
这篇关于使用 "1 < 解析 thymeleaf 模板时出错0"的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!