当前位置:
首页 >
前端技术
> javascript
>内容正文
javascript
SpringBoot中使用thymeleaf的switch来实现if-else if -else的效果
生活随笔
收集整理的这篇文章主要介绍了
SpringBoot中使用thymeleaf的switch来实现if-else if -else的效果
小编觉得挺不错的,现在分享给大家,帮大家做个参考.
场景
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>
总结
以上是生活随笔为你收集整理的SpringBoot中使用thymeleaf的switch来实现if-else if -else的效果的全部内容,希望文章能够帮你解决所遇到的问题。
- 上一篇: SpringBoot中对thymelea
- 下一篇: SpringBoot+Thymeleaf