7.2 switch声明
还有一种有条件地表示内容的方法,与Java里的switch结构等价:th:switch / 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></div>
注意:一旦一个th:case属性为true,在同一个switch上下文里的其它的th:case属性会被求值为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>
