我正在使用 a 填充表格<tr th:each>
我想放置一个 if 语句来评估该值是否为空,如果该值为空,我想放置此“--”而不是“null”。
我怎样才能使用th:if
或其他类似的功能我是新使用百里香?
这是我的代码:
<table id="datatable_fixed_column" class="table table-striped table-bordered" width="100%">
<thead>
<tr>
<th>name</th>
<th>lastname</th>
<tr>
<tbody>
<tr th:each="nodeInfo : ${listOfData}">
<td th:if="${nodeInfo.name} == 'null'"> -- </td>
<td th:if="${nodeInfo.name} != 'null'" th:text="${nodeInfo.name}"></td>
编辑:代码已编辑及其工作原理
只需将您的代码更改为:
<tr th:each="nodeInfo : ${listOfData}">
<td th:if="${nodeInfo.name} == null">This is the value if the name is null</td>
<td th:if="${nodeInfo.name} != null">This is the value if the name is NOT null</td>
</tr>
或者更简洁地你可以写:
<tr th:each="nodeInfo : ${listOfData}">
<td th:if="!${nodeInfo.name}">This is the value if the name is null</td>
<td th:if="${nodeInfo.name}">This is the value if the name is NOT null</td>
</tr>
这是有效的,因为${nodeInfo.name}
被评估为true
when name
不为空
您还可以探索使用th:unless
而不是使用!=
查看this http://www.thymeleaf.org/doc/usingthymeleaf.html#simple-conditionals-if-and-unless文档的一部分以获取更多详细信息。
本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系:hwhale#tublm.com(使用前将#替换为@)