我使用 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/