直接上代码
<table class="table table-striped table-hover table-bordered">
<thead>
<tr>
<th data-field="username">账号</th>
<th data-field="cretae_time">注册时间</th>
</tr>
</thead>
<tbody class="table-condensed">
<tr th:if="${userModel.userList.size() -1} eq 0">
<td colspan="10" style="color:red; text-align:center;"><b>暂无用户信息!</b></td>
</tr>
<tr th:each="user : ${userModel.userList}" th:if="${(user.username) ne (#authentication.name)}">
<td th:text="${user.username} ?: '(空)'">账号</td>
<td th:text="${#dates.format(user.create_time,'yyyy年MM月dd日 HH:mm:ss')} ?: '(空)'">注册时间</td>
</tr>
</tbody>
</table>
注解:
关键代码:如果后台返回过来的userModel.userList的长度减1等于0就显示"暂无用户信息",因为即使只有当前登录用户时也显示"暂无用户信息"
th:if="${userModel.userList.size() -1} eq 0}"
关键代码:${#authentication.name} ==>获取当前登录的用户名如果table表格中的user.username等于当前登录用户则不显示
th:if="${(user.username) ne (#authentication.name)}
代码拓展与总结:
#当前用户名
${#authentication.name}
#当前用户的xxx属性
${#authentication.principal.xxx}
2019.07.01笔,后续会继续更新,多多支持