JSTL中是否有if-else标签? spring
除了skaffman答案外,简单的if-else也能够像这样使用三元运算符 this
<c:set value="34" var="num"/> <c:out value="${num % 2 eq 0 ? 'even': 'odd'}"/>
没有if-else,只有。 spa
<c:if test="${user.age ge 40}"> You are over the hill. </c:if>
您能够选择在如下状况下使用choose-when: code
<c:choose> <c:when test="${a boolean expr}"> do something </c:when> <c:when test="${another boolean expr}"> do something else </c:when> <c:otherwise> do this when nothing else is true </c:otherwise> </c:choose>
我只使用了两个if标签,觉得我会添加一个答案,以防其余人使用它: orm
<c:if test="${condition}"> ... </c:if> <c:if test="${!condition}"> ... </c:if>
虽然技术上不是if-else
自己的行为是相同的,避免使用的笨重的方式choose
标签,因此要根据您的要求有多复杂,这多是可取的。 pdo
是的,可是笨拙,例如 get
<c:choose> <c:when test="${condition1}"> ... </c:when> <c:when test="${condition2}"> ... </c:when> <c:otherwise> ... </c:otherwise> </c:choose>
您必须使用如下代码: it
与<%@ taglib prefix="c" uri="http://www.springframework.org/tags/form"%>
io
和 form
<c:select> <option value="RCV" ${records[0].getDirection() == 'RCV' ? 'selected="true"' : ''}> <spring:message code="dropdown.Incoming" text="dropdown.Incoming" /> </option> <option value="SND" ${records[0].getDirection() == 'SND'? 'selected="true"' : ''}> <spring:message code="dropdown.Outgoing" text="dropdown.Outgoing" /> </option> </c:select>