场景
SpringBoot中使用thymeleaf的开关语句实现if-else if -else的效果。
Switch使用示例:
<div th:switch="${user.role}">
<p th:case="'admin'">User is an administrator</p>
<p th:case="#{roles.manager}">User is a manager</p>
</div>
请注意,只要一个:case属性计算为true,其它每一个th:case属性在相同的switch中认定为false。
默认选项指定为th:case="*":
<div th:switch="${user.role}">
<p th:case="'admin'">User is an administrator</p>
<p th:case="#{roles.manager}">User is a manager</p>
<p th:case="*">User is some other thing</p>
</div>
实现
<div th:switch="${info.status}">
<th th:case="00">完成</th>
<th th:case="01">异常</th>
<th th:case="*">未知状态</th>
</div>