是否有任何标签可以有条件地呈现 HTML 块。例如:Struts 有:
<logic:present name="someForm" property="someProperty">
//Code block
</logic:present>
例如:JSF 有:
<h:panelGrid rendered="#{not empty someList}">
//Some code block
</h:panelGrid>
Spring MVC中有类似的东西吗?
是否有任何标签可以有条件地呈现 HTML 块。例如:Struts 有:
<logic:present name="someForm" property="someProperty">
//Code block
</logic:present>
例如:JSF 有:
<h:panelGrid rendered="#{not empty someList}">
//Some code block
</h:panelGrid>
Spring MVC中有类似的东西吗?
普通的旧 JSTL 来拯救你!
Spring MVC 的美妙之处在于它不像其他框架那样添加大量冗余标签库。您始终可以依赖 JSTL 进行此类检查,这是 JSP 规范的一部分。
<c:if test="${not empty someList}">
</c:if>
JSTL:
<c:if test="${!empty someForm.someProperty}">
</c:if>
你可以使用通用的 JSP/JSTL 标签库
<%@ taglib uri="http://java.sun.com/jsp/jstl/core" prefix="c"%>
<c:choose>
<c:when test="${condition}">
something
</c:when>
<c:otherwise>
something else
</c:otherwise>
</c:choose>
或者
<c:if test="${condition}">
something
</c:if>
使用 c:if 据我所知没有其他条件