struts2项目迁移为springmvc项目时jsp标签变化记录

1、引入spring标签(使用Struts时也要引入Struts标签,如s标签)

  1. <%@taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core"%>  
  2. <%@taglib prefix="fmt" uri="http://java.sun.com/jsp/jstl/fmt" %>   
  3. <%@taglib prefix="spring" uri="http://www.springframework.org/tags" %>   
2、标签使用

2.1 判断:


  1. 在Struts中:  
  2. <s:if test="dentity.type==1"><b class="cnm_lpt"></b>  
  3. </s:if>  
  4. <s:else><b class="cnm_lps"></b>  
  5. </s:else>  
  6.   
  7. 在spring中:  
  8. 一个条件:<c:if test="${device.typeId==7}">测试</c:if>  
  9. 多个条件使用choose标签包裹:  
  10. <c:choose>  
  11.     <c:when test="${device.typeId == 7 }"><b class="cnm_lpt"></b></c:when>  
  12.     <c:otherwise><b class="cnm_lps"></b></c:otherwise>  
  13. </c:choose>  

2.2 遍历

  1. 在Struts中:  
  2. <s:iterator value="%{resultList}" id="data" status="sta">  
  3.     <td>物联网适配器编号:</td>  
  4.     <td><a href="viewdetail.action?detailId=<s:property value="id"/>&deviceKey=<s:property value="devicekey"/>"><s:property value="code"/> </a></td>  
  5. </s:iterator>  
  6.   
  7. 在spring中:  
  8. <c:forEach items="${rows }" var="row" varStatus="vs">  
  9.               <tr>  
  10.                 <input type="hidden" id="typeId_${row.adaptorCode}" value="${row.typeId}"/>  
  11.                 <td>  
  12.                  <a href="jkxq?deviceId=${row.id }&adaptorCode=${row.adaptorCode}&typeId=${row.typeId}&sort=happen_time&order=DESC" style="text-decoration:underline;">${row.code }</a>  
  13.                 </td>  
  14.                  
  15.                 </tr>  
  16. </c:forEach>  

2.3 变量

  1. 在Struts中:  
  2. <p>变频器型号:<i><s:property value="dentity.model"/></i></p>  
  3.   
  4. 在spring中:  
  5. <p>变频器型号:<i>${device.model }</i></p>  

2.4 格式化

时间格式化:

  1. <fmt:formatDate value="${record.operateTime}" pattern="yyyy-MM-dd HH:mm:ss"/>  
2.5 其他 input 隐藏框

  1. 在Struts中:  
  2. <s:hidden name="dentity.type" id="dtype"></s:hidden>  
  3.   
  4. 在spring中:  
  5. <input type="hidden" id="dtype" value="${device.typeId }"/>  

2.6 国际化


  1. spring国际化标签  
  2. <spring:message code="project.monitor.adaptor.code" />  

转载来源 https://blog.csdn.net/yangwen123222/article/details/79375389

猜你喜欢

转载自blog.csdn.net/long2010110/article/details/80745888