在Grails中,g:if
和g:unless
是用于根据条件显示内容的Groovy标签。如果测试多个条件,可以使用g:choose
和g:when
标签组合使用,如下所示:
<g:choose>
<g:when test="${condition1}">
<p>Condition 1 is true</p>
</g:when>
<g:when test="${condition2}">
<p>Condition 2 is true</p>
</g:when>
<g:otherwise>
<p>No condition is true</p>
</g:otherwise>
</g:choose>
其中,condition1
和condition2
是要测试的条件,可以根据实际情况设置具体的条件。如果第一个条件测试结果为true
,则显示Condition 1 is true
;如果第二个条件测试结果为true
,则显示Condition 2 is true
;如果两个条件都不满足,则显示No condition is true
。
需要注意的是,g:choose
标签内的g:when
标签的数量可以根据实际需求进行添加,而g:otherwise
标签是可选的,如果不需要默认情况,可以不添加。
领取专属 10元无门槛券
手把手带您无忧上云