【发布时间】:2015-06-21 20:26:53
【问题描述】:
简而言之
我想在 thymeleaf 中使用 switch 语句,一旦将逻辑写入多个 case 语句。
详细说明
我想在百里香中实现这个
switch(status.value){
case 'COMPLETE':
case 'INVALID':
//print exam is not active
break;
case 'NEW':
//print exam is new and active
break;
}
我当前的 thymleaf 代码因运行时错误而失败
<div th:switch="${status.value}">
<div th:case="'COMPLETE','INVALID'">
<!-- print object is not active -->
</div>
<div th:case="NEW'">
<!-- print object is new and active -->
</div>
</div>
但上面的代码失败并出现错误
org.thymeleaf.exceptions.TemplateProcessingException: Could not parse as expression: "'COMPLETE','INVALID'"...
注意:我知道上述错误消息的原因。我所需要的只是知道一种为单个输出实现多案例切换的方法
【问题讨论】:
-
没有办法让它成为你想要的样子。如 pens-fan-69 所述,如果您希望避免代码重复,只需在两种情况下都使用片段。
标签: java spring-boot thymeleaf