下面的代码显示<s:a>
了从 1 到 10 使用 Struts 的链接。
<s:set var="currentPage" value="2"/>
<s:set var="begin" value="1"/>
<s:set var="end" value="10"/>
<s:iterator begin="%{begin}" end="%{end}" step="1" var="row" status="loop">
<s:if test="%{#currentPage eq #row}"> <!--???-->
<span><s:property value="%{#row}"/></span>
</s:if>
<s:else>
<s:url id="pageURL" action="someAction" escapeAmp="false">
<s:param name="currentPage" value="%{row}"/>
</s:url>
<s:a href="%{pageURL}" name="btnPage" cssClass="paging">
<s:property value="%{#row}"/>
</s:a>
</s:else>
</s:iterator>
当currentPage
(which is 2) 匹配条件表达式test="%{#currentPage eq #row}"
时,它只使用<s:property>
inside显示文本,<span>
而不是显示链接。没关系。
当我使用这些相同的标签但在其相应的操作类中使用适当的属性时,
<s:iterator begin="%{begin}" end="%{end}" step="1" var="row" status="loop">
<s:if test="%{currentPage eq #row}"> <!--???-->
<span class="current"><s:property value="%{#row}"/></span>
</s:if>
<s:else>
<s:url id="pageURL" action="someAction" escapeAmp="false">
<s:param name="currentPage" value="%{row}"/>
</s:url>
<s:a href="%{pageURL}" name="btnPage" cssClass="paging">
<s:property value="%{#row}"/>
</s:a>
</s:else>
</s:iterator>
在这种情况下,currentPage
(和所有其他)是Long
动作类中的类型属性。在这里,关于前一个案例的条件测试test="%{#currentPage eq #row}"
被评估为false。
它需要省略#
before currentPage
。因此,表达式变为test="%{currentPage eq #row}"
(否则,它总是计算为假)。
我不明白为什么第一种情况需要test="%{#currentPage eq #row}"
,第二种情况需要test="%{currentPage eq #row}"
?有什么我可能会丢失的吗?