SpringMVC 自带标签没有Struts2的好用。。。
1.使用s:if判断字符串
2.s:if判断null
3.c:if判断是否为null
- <s:if test="name!='doom'">
- .....
- </s:if>
- <s:else>
- ....
- </s:else>
2.s:if判断null
- <s:if test="list!=null && list.size!=0">
- <table border="1">
- <tr><td>table1</td><tr>
- <s:iterator value="list" id="u" status="st">
- <tr>
- <td><s:property value="#st.index" /></td>
- <td> <s:property value="[color=red]#u.id[/color]"/></td>
- <td> <s:property value="[color=red]username[/color]"/></td>
- <td> <s:property value="password"/></td>
- <tr>
- </s:iterator>
- </table>
- </s:if>
3.c:if判断是否为null
- <c:if test="${!empty list}">
- <table border="1">
- <tr><td colspan="3">table2</td><tr>
- <c:forEach var="u" items="${list}" varStatus="sta">
- <tr>
- <td>${sta.index}</td>
- <td align="center"> ${u.id} </td>
- <td align="center"> ${u.username } </td>
- <td align="center"> ${u.password} </td>
- </tr>
- </c:forEach>
- </table>
- </c:if>
4.c:标签没有 else标签 可以通过 c:choose c:when c:otherwise实现
- <tr>
<td>学历</td>
<td>
<select name="education">
<c:if test="${employ.education==null }">
<option value="" selected="selected">请选择</option>
</c:if>
<c:choose>
<c:when test="${employ.education=='高中'}">
<option value="高中" selected="selected">高中</option>
</c:when>
<c:otherwise>
<option value="高中">高中</option>
</c:otherwise>
</c:choose>
<c:choose>
<c:when test="${employ.education=='大专'}">
<option value="大专" selected="selected">大专</option>
</c:when>
<c:otherwise>
<option value="大专">大专</option>
</c:otherwise>
</c:choose>
<c:choose>
<c:when test="${employ.education=='本科'}">
<option value="本科" selected="selected">本科</option>
</c:when>
<c:otherwise>
<option value="本科">本科</option>
</c:otherwise>
</c:choose>
<c:choose>
<c:when test="${employ.education=='研究生'}">
<option value="研究生" selected="selected">研究生</option>
</c:when>
<c:otherwise>
<option value="研究生">研究生</option>
</c:otherwise>
</c:choose>
<c:choose>
<c:when test="${employ.education=='博士'}">
<option value="博士" selected="selected">博士</option>
</c:when>
<c:otherwise>
<option value="博士">博士</option>
</c:otherwise>
</c:choose>
</select>
</td>
</tr>