实现“上一页”“第几页”“下一页”(当前页数从Action中获取)
package cn.ict.mp.webservice;import java.util.HashMap;import java.util.List;import java.util.Map;import org.apache.struts2.ServletActionContext;import cn.ict.mp.bean.UserInfo;import cn.ict.mp.service.DataManage;import com.opensymphony.xwork2.ActionSupport;public class ActionUserList extends ActionSupport {/** * */private static final long serialVersionUID = -6652169340293756648L;private Map<String, Object> dataMap = new HashMap<String, Object>();public Map<String, Object> getDataMap() {return dataMap;}private Integer pageNo;private Integer totalSize;private Integer totalPage; private Integer pageSize = 5; public Integer getTotalPage() {return totalPage;} public Integer getPageNo() {return pageNo;} public void setPageNo(Integer pageNo) {this.pageNo = pageNo;} public String execute() throws Exception {/** * 定义action返回格式 */ServletActionContext.getResponse().setContentType("application/json;charset=UTF-8");ServletActionContext.getResponse().setCharacterEncoding("UTF-8"); //分页显示用户信息列表List<UserInfo> dataList = DataManage.getUserList(pageNo, pageSize);totalSize = DataManage.getUserListSize();//总页数向上取整totalPage = (int)Math.ceil((double)totalSize/pageSize);this.dataMap.put("userList", dataList);return SUCCESS;}}
?