如何检查 JSTL <c:out> 标签中的 null?

How to check null in JSTL <c:out> tag?

我正在寻找在 table 单元格中插入变量的可能性,或者如果值结果为空,则在单元格中写入另一个文本,但具有不同的样式。我怎样才能做到这一点?

这个显然不起作用:

<c:out value="${data.onlineData.state}" default="<span class="customercare-null"><spring:theme code="productOffline.null" /></span>" escapeXml="false" />

对于我要实现的目标,这是正确的语法吗?

<c:out value="${data.onlineData.state}">
    <span class="customercare-null"><spring:theme code="productOffline.null" /></span>
</c:out>

我知道 c:choose 可以解决这个问题,但我想知道上面提供的代码是否也是合法的

提前致谢

使用<c:if>检查空值

<c:if test="${empty data.onlineData.state}">
    <span class="customercare-null"><spring:theme code="productOffline.null" /></span>
</c:if>
<c:if test="${not empty data.onlineData.state}">
   <c:out value="${data.onlineData.state}" />
</c:if>

或使用<c:choose>:

<c:choose>
    <c:when test="${empty data.onlineData.state}">
        <span class="customercare-null"><spring:theme code="productOffline.null" /></span>
    </c:when>
    <c:otherwise>
       <c:out value="${data.onlineData.state}" />
    </c:otherwise>
</c:choose>

would this be correct syntax for what I'm trying to achieve?

如果你使用

<c:out value="${data.onlineData.state}">
    <span class="customercare-null"><spring:theme code="productOffline.null" /></span>
</c:out>

然后<span class="customercare-null"><spring:theme code="productOffline.null" /></span>将显示为文本。 Html 组件不会渲染。