ssc源码出售 Thymeleaf页面三元运算符

根据0、1显示用户性别
可以使用三元运算符,ssc源码出售【企 娥:217 1793 408】两种写法

写在括号内

<td th:text="${emp.gender==0?'女':'男'}"></td>
1
写在括号外

<td th:text="${emp.gender}==0?'女':'男'"></td>
1
推荐
写在括号外

<table class="table table-striped table-sm">
<thead>
<tr>
<th>#</th>
<th>lastName</th>
<th>email</th>
<th>gender</th>
<th>department</th>
<th>birth</th>
<th>操作</th>
</tr>
</thead>
<tbody>
<tr th:each="emp:${emps}">
<td th:text="${emp.id}"></td>
<td>[[${emp.lastName}]]</td>
<td th:text="${emp.email}"></td>
<td th:text="${emp.gender}==0?'女':'男'"></td>
<td th:text="${emp.department.departmentName}"></td>
<td th:text="${#dates.format(emp.birth, 'yyyy-MM-dd HH:mm')}"></td>
<td>
<a class="btn btn-sm btn-primary" th:href="@{/emp/}+${emp.id}">编辑</a>
<button th:attr="del_uri=@{/emp/}+${emp.id}" class="btn btn-sm btn-danger deleteBtn">删除
</button>
</td>
</tr>
</tbody>
</table>

猜你喜欢

转载自blog.51cto.com/13945939/2166311