html - 如何在 thymeleaf 中将值设置为 "NULL"

标签 html css thymeleaf

我使用 thymeleaf 作为 UI 框架。我正在从数据库中提取数据并将其存储为对象。当我在表格中显示我的值时,有些单元格是空白的。如何输入“NULL”值而不是空白?

<table>
    <tr>
        <th>id</th>
        <th>name</th>
        <th>age</th>
        <th>years in school</th>
    </tr>
    <tr th:each="student : ${studentinfo}">
        <td th:text="${student.id}"></td>
        <td th:text="${student.name}"></td>
        <td th:text="${student.age}"></td>
        <td th:text="${student.years}">NULL</td>
        <!-- attempted -->
        <td th:text="${student.years != null} ? ${student.years}">NULL</td>
    </tr>
</table>

有些学生多年来null。但是当我在用户界面中显示它时,它只是一个空白单元格。如果单元格为空白,我想显示“NULL”。

最佳答案

只需使用三元表达式的其余部分即可:P

<td th:text = "${student.years != null ? student.years : 'NULL'}" />

关于html - 如何在 thymeleaf 中将值设置为 "NULL",我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/42300785/

相关文章:

html - 缩放浏览器窗口尺寸较小时如何使用 Bootstrap 隐藏其中一个 div

css - 为什么用于设置表格样式设置的重叠标签(显然)会做同样的事情?

java - spring-data-jpa 的查询注解

javascript - 如何根据数据调整 Angular 数据表的高度

java - (SPRING) 从 postgresql 数据库获取用户信息并在 thymeleaf html 中打印

java - Thymeleaf 到 madal jquery

html - 内联导航示例不起作用

html - IE9+ 中的负边距底部允许滚动太远

javascript - 到达页面底部时,粘性导航栏会闪烁

javascript - 如何在 svg 之前也始终在前景中获取导航栏?