thymeleaf“$ {} user.display? $ {} user.display: '空值!'”

问题描述 投票:-1回答:1

我有问题。我想显示文本时的值不为空。

<tr th:each="user : ${users}">      
    <td>
    <span  th:text="${user.display} ? ${user.display} : 'null value!'"> NOW is work</span>
    </td>
    </tr>   
thymeleaf
1个回答
0
投票

我想你可以使用1个变量表达式${}了点。

尝试

<tr th:each="user : ${users}">      
    <td>
        <span  th:text="${user.display != null || user.display != '' ? user.display : 'null value!'}"> NOW is work</span>
    </td>
</tr> 

编辑

我只注意到你怎么做你的病情,所以我已经编辑我的答案。也没有什么错,你怎么使用变量表达式,是我不好。

什么是user.display的价值?我认为它没有布尔,因为如果它是你的方式做你的情况是错误的。

${user.display} ? ${user.display} : 'null value!' // true if the value of user.display is boolean **true**

${user.display != null || user.display != ''} ? ${user.display} : 'null value!'} // true if the value of user.display is not null or not '' empty string

尝试

<tr th:each="user : ${users}">      
    <td>
        <span  th:text="${user.display != null || user.display != ''} ? ${user.display} : 'null value!'}"> NOW is work</span>
    </td>
</tr> 
© www.soinside.com 2019 - 2024. All rights reserved.