Struts2ognl标签加法运算

来源:互联网 发布:斗拱尺寸算法 编辑:程序博客网 时间:2024/05/24 03:43

在我们使用Struts2<s:iterator  value ="list" status ="status">标签的时候,我们通常序号都是 <s:property value="#status.count" />

但当翻页的时候,序号仍然是从1开始,但我们希望是从下一页的序号开始所以就得使用用 set标签 然后进行 OGNL变量加法运算:

<s:set name ="page_index" value = "#status.count -1" scope="request" ></set>  使用set标签把 count值放在ognl变量page_index中;

然后再使用 <s:property value="%{pageUtil.startIndex + #reqest.page_index}"  />  也可以写成这样 <s:property value="pageUtil.startIndex + #reqest.page_index"  />

:pageUtil.startIndex 是指每页的起始序号;

总结:

OGNL表达式运算方式:

1、纯数字加法
<s:property value="1+2"/>
<s:property value="%{1+2}"/>


2、有变量的加法(变量需为数字类型,如果其中一个为字符串则为字符串相连)
<s:property value="msgPK+msgPK"/>
<s:property value="%{msgPK+msgPK}"/>
<s:property value="#stat.index+1"/>