如何在th中使用多个条件:如果标签使用thymeleaf [英] How to have multiple condition in an th:if tag using thymeleaf

查看:6640
本文介绍了如何在th中使用多个条件:如果标签使用thymeleaf的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我使用 thymeleaf 以三种不同的颜色呈现文本。

因此,我迄今为止测试的代码值为:

  th:if =$ {evaluation}& gt; 50
th:if =$ {evaluation}& lt; 30

而且效果很好。



但是第三个测试是针对这两者之间的值。
所以我试过:

  th:if =($ {evaluation}& lt; 49)&和;($ {evaluation}& gt; 29)

但它不工作,解析出现这个错误:

  org.thymeleaf.exceptions.TemplateProcessingException:无法解析为表达式:($ {evaluation }< 49)& and;($ {evaluation}> 29)(/property.html:41)

当然,由于前两项工作正常,这些行之间有标签。

也许操作数不正确,但是百里香的文档这些操作数并不是真的很明确。



欢迎您提供所有建议!



更新:

  th:if =$ {evaluation& lt; 49 and evaluation& gt; 29}

问题解决了!

解决方案

我从百里香论坛得到了答案。做到这一点的方法是:

  th:if =$ {evaluation& lt; 49 and evaluation& gt; 29}

问题解决了!


I have a text to render in three different possible colors using thymeleaf.

So the code I've made so far to test the value is:

th:if="${evaluation} &gt; 50"
th:if="${evaluation} &lt; 30"

And that works well.

But the third test is for values between those two. So I tried:

th:if="(${evaluation} &lt; 49) &and; (${evaluation} &gt; 29)"

but it's not working, I've got this error while parsing:

org.thymeleaf.exceptions.TemplateProcessingException: Could not parse as expression: "(${evaluation} < 49) &and; (${evaluation} > 29)" (/property.html:41)

Of course, these lines are between tags since the first two are working properly.

Maybe the and operand is not correct, but the documentation of thymeleaf is not really explicit on those operands.

All ideas are welcome!

Update: I got the answer from the thymeleaf forum. The way to do it is:

th:if="${evaluation &lt; 49 and evaluation &gt; 29}"

Problem solved!

解决方案

I got the answer from the thymeleaf forum. The way to do it is :

th:if="${evaluation &lt; 49 and evaluation &gt; 29}"

Problem solved !

这篇关于如何在th中使用多个条件:如果标签使用thymeleaf的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆