struts2标签有if…..else
<s:if></if><s:else></s:else>
如果要用c标签来表示if…..else 的效果
<c:choose> <c:when test=....></when> 相当于if <c:otherwise></c:otherwise> 相当于else</c:choose>
遍历集合 假设遍历personList 看他们的不同写法
<s:iterator value="personList " var="var"> <s:property value="#var.name" /> </s:iterator>
换成c标签
<c:forEach items=${personList } var="var"> //这里写${personList} <c:out value="${var.name}" /> //这里用的是$符号</c:forEach>
似乎c标签都要用${} 来获取值, s标签似乎要简单些。
在看一下<s:set> <c:set> 之间的用法区别
<c:set var="str" value="${var.proInfo.id }0000"></c:set> <c:set var="p1" value="${str.substring(0,2) }"></c:set> <c:set var="p2" value="${str.substring(0,4) }"></c:set> <c:set var="picpath" value="artwork/${p1 }/${p2 }/${var.proInfo.id }"></c:set>如果c标签要获取上面str的值 直接使用<c:out value="${str}" /> 就能获取到该值。上面p1就使用了str的值看一下s标签的用法<s:set name="str" value="#var.proInfo.id+'0000'"></s:set> <s:set name="p1" value="#str.substring(0,2)"></s:set><s:set name="p2" value="#str.substring(0,4)"></s:set><s:set name="picpath" value="'artwork/'+#p1+'/'+#p2+'/'+#var.proInfo.id"></s:set>如果s标签要获取上面str的值 直接使用<s:property value="#str" /> 就能获取到该值。 上面p1就使用了str的值还是来看c:if 和 s:if 中test的写法<c:forEach var="art" items="${productInfoList}">var att = "关注", flag = 0;<c:forEach var="atten" items="${productAttentionList}"><c:if test="${atten.productInfo.id==art.id}">att = "已关注"; flag = 1;</c:if> </c:forEach></c:forEach> 回到s:if标签中的test写法<s:iterator var="art" value="productInfoList">var att = "关注", flag = 0;<s:iterator var="atten" value="productAttentionList"><s:if test="#atten.productInfo.id==#art.id">att = "已关注"; flag = 1;</s:if> </s:iterator></s:iterator>
- 1
- 2
- 3
- 4
- 5
- 6
- 7
- 8
- 9
- 10
- 11
- 12
- 13
- 14
- 15
- 16
- 17
- 18
- 19
- 20
- 21
- 22
- 23
- 24
- 25
- 26
- 27
- 28
- 29
- 30
- 31
- 32
- 33