.在action里加上totalpage属性,GET SET方法
2.第一种写法(推荐)
<s:iterator value="new int[totalpage]" status="i">
<s:property value="#i.index+1"/>
</s:iterator>
第二种写法,较第一种慢
<s:bean name="org.apache.struts2.util.Counter" id="i">
<s:param name="first" value="1"/> <s:param name="last" value="maxNum"/>
<s:iterator>
<s:property value="#i.current - 1"/>
</s:iterator>
</s:bean>
3.struts2.0和2.1上在iterator这个标签上有区别
如果是2.1把id改成var就可以了
在实际情况中可能不仅需要遍历出页码,还可能需要返回所选择的当前页,就第一种方法给出实例
到:第<select name="currentPage">
<s:iterator value="new int[totalPage]" status="st">
<s:if test='currentPage==#st.index+1'>
<option value='<s:property value="#st.index+1"/>'
selected="selected">
<s:property value="#st.index+1" />
</option>
</s:if>
<s:else>
<option value='<s:property value="#st.index+1" />'>
<s:property value="#st.index+1" />
</option>
</s:else>
</s:iterator>
</select>页
本文介绍使用Struts2框架实现分页功能的方法,包括设置totalpage属性,并通过两种方式展示分页链接及如何返回当前页选项。第一种方法利用<s:iterator>标签直接生成页码,第二种方法则通过Counter组件实现。
2万+

被折叠的 条评论
为什么被折叠?



