Warning: file_get_contents(/data/phpspider/zhask/data//catemap/5/spring-mvc/2.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Spring Thymeleaf开关块返回不正确的值_Spring_Spring Mvc_Thymeleaf - Fatal编程技术网

Spring Thymeleaf开关块返回不正确的值

Spring Thymeleaf开关块返回不正确的值,spring,spring-mvc,thymeleaf,Spring,Spring Mvc,Thymeleaf,我在my thymeleaf页面中有一个切换块,根据用户的声誉分数显示图像: <h1> <span th:text="#{user.reputation} + ${reputation}">Reputation</span> </h1> <div th:if="${reputation lt 0}"> <img th:src="@{/css/img/troll.png}"/> </div> <

我在my thymeleaf页面中有一个切换块,根据用户的声誉分数显示图像:

<h1>
    <span th:text="#{user.reputation} + ${reputation}">Reputation</span>
</h1>
<div th:if="${reputation lt 0}">
    <img th:src="@{/css/img/troll.png}"/>
</div>
<div th:if="${reputation} == 0">
    <img th:src="@{/css/img/smeagol.jpg}"/>
</div>
<div th:if="${reputation gt 0} and ${reputation le 5}">
    <img th:src="@{/css/img/samwise.png}"/>
</div>
<div th:if="${reputation gt 5} and ${reputation le 15}">
    <img th:src="@{/css/img/frodo.png}"/>
</div>
<div th:if="${reputation gt 15}">
    <img th:src="@{/css/img/gandalf.jpg}"/>
</div>

名声
此语句始终返回smeagol(因此信誉为0),即使此用户的信誉为7:

编辑:

我错了,图像显示的是流氓路线:

<!--<img th:src="@{/css/img/smeagol.jpg}"/>-->

但是我把它注释掉了。现在没有图像显示

EDIT2:

更改了我的比较器(参见原始帖子),现在我得到以下错误:

 The value of attribute "th:case" associated with an element type "div" must not contain the '<' character.
与元素类型“div”关联的属性“th:case”的值不能包含“更改

  <div th:case="0">
    <img  th:src="@{/css/img/smeagol.jpg}"/>
  </div>


根据,Thymeleaf的
switch
语句的工作原理与Java的类似,示例也给出了同样的建议

换言之:你做不到

<th:block th:switch="${reputation}">
    <div th:case="${reputation} < 0">
[...]

这仍然显示smeagol,在这种情况下,它应该显示frodo的图像,因为声誉是7。@Audiosleef检查您的另一台压实机是否工作正常,您认为另一台压实机是什么意思?@Audiosleef如
gt
lt
将其更改为le,如thymeleaf文档中所述,现在出现错误。我已经修改了我的原始问题,它仍然给我以下错误:与元素类型“div”关联的属性“th:if”的值不能包含“Got it!”!正确的方法是:谢谢你给我指出了正确的方向。很好,很高兴你找到了解决办法!
<th:block th:switch="${reputation}">
    <div th:case="${reputation} < 0">
[...]
<th:block th:switch="${reputation}">
    <div th:case="0">
[...]
<div th:if="${reputation} < 0">
    <img  th:src="@{/css/img/troll.png}"/>
</div>