kro*_*old 106

使用empty关键字

<c:if test="${not empty post}">
   <h3>${post.title}</h3>   
</c:if>
Run Code Online (Sandbox Code Playgroud)

  • 这绝对是最好的方式.我相信它也会检查"null". (2认同)

hej*_*007 11

你也可以用'!' 而不是'不':

<c:if test="${!empty post}">
    <h3>${post.title}</h3>
</c:if>
Run Code Online (Sandbox Code Playgroud)