小编noc*_*yto的帖子

Thymeleaf th:每个用th过滤:if

我需要迭代,并创建<span>针对每个元件componentcomponents,其具有阵列name'MATERIAL'

我的代码如下

<span th:each="component : ${body.components}" 
      th:object="${component}">
        <button th:if="*{name} == 'MATERIAL'" 
                th:text="*{title}"></button>
</span>
Run Code Online (Sandbox Code Playgroud)

这段代码一切正常,直到它产生一组空<span>元素,如果name它不相等'MATERIAL'.我不希望这个空<span>元素被创建.

我也试过以下

<span th:each="component : ${body.components}" 
      th:object="${component}"
      th:if="*{name} == 'MATERIAL'">
         <button th:text="*{title}"></button>
</span>
Run Code Online (Sandbox Code Playgroud)

这导致空输出并且根本不打印任何内容.有人可以帮我这个.

java spring spring-mvc thymeleaf spring-boot

9
推荐指数
1
解决办法
1万
查看次数

标签 统计

java ×1

spring ×1

spring-boot ×1

spring-mvc ×1

thymeleaf ×1