如何在th:text中显示Thymelaf中的空白数据



我正在尝试使用Thymelafifunless,但它不起作用。我想做的是,我想检查statusNm变量的值是否为"Approved",然后它将显示内容,否则它将留空。

但我无法实现。请给我一个解决方案。

<th>Approved Date</th>
<td th:if="${obj.statusNm}=='Approved'" th:text="${obj.modifyDt}"></td>
<td th:unless="${obj.statusNm}" th:text=""></td>
<th>Approved By</th>
<td th:if="${obj.statusNm}=='Approved'" th:text="${obj.modifier}"></td>
<td th:unless="${obj.statusNm}" th:text=""></td>

作为替代方案,您可以查看Conditional表达式并直接在th:text属性中计算条件。。。

<th>Approved Date</th>
<td th:text="${obj.statusNm=='Approved'} ? ${obj.modifyDt}"></td>
<th>Approved By</th>
<td th:text="${obj.statusNm=='Approved'} ? ${obj.modifier}"></td>

等号检查必须在花括号内,如下所示:

<th>Approved Date</th>
<td th:if="${obj.statusNm=='Approved'}" th:text="${obj.modifyDt}"></td>
<td th:unless="${obj.statusNm=='Approved'}" th:text=""></td>

最新更新