Hibernate和jQuery插件flexgrid集成分页
来源:互联网 发布:马自达cx5 知乎 编辑:程序博客网 时间:2024/05/02 14:03
Hibernate和jQuery插件flexgrid集成分页
1.在Struts的Action中这样写:
package com.hithd.iswmanagement.Actions.StaffAction;import java.util.List;import javax.servlet.http.HttpServletRequest;import javax.servlet.http.HttpServletResponse;import org.apache.struts.action.Action;import org.apache.struts.action.ActionForm;import org.apache.struts.action.ActionForward;import org.apache.struts.action.ActionMapping;import com.hithd.iswmanagement.Services.ShowStaffService;/** * 显示职工信息Action. * @author Administrator * */public class ShowStaffAction extends Action { private ShowStaffService showStaffService; public void setShowStaffService(ShowStaffService showStaffService) { this.showStaffService = showStaffService; } @Override public ActionForward execute(ActionMapping mapping, ActionForm form, HttpServletRequest request, HttpServletResponse response) throws Exception { /* 从前台页面取得当页的页号. */ int pageNo = Integer.parseInt(request.getParameter("pageNo")); /* 定义每页显示的记录数. */ int pageSize = 5; /* Hibernate内置分页的起始记录号. */ int firstResult = 0; /* Hibernate内置分页的终止记录号. */ int maxResult = pageSize; /* 从前台拿到提交的按钮状态,用来判断分页操作. */ String buttonstate = request.getParameter("buttonstate"); /* 计算出总共有多少页. */ List allstaffList = this.showStaffService.ShowAllStaff(); int totalRecald = allstaffList.size(); int totalPage = totalRecald / pageSize; if ((totalRecald % pageSize) > 0) { totalPage = totalRecald / pageSize + 1; } /* 前台提交的是首页. */ if (buttonstate.equals("First")) { pageNo = 1; } /* 前台提交的是尾页. */ if (buttonstate.equals("Last")) { pageNo = totalPage; } /* 当页面已经到首页. */ if (pageNo < 1) { pageNo = 1; } /* 当前页已经倒尾页. */ if (pageNo > totalPage) { pageNo = totalPage; } /* 当分页时所有的页号必须从1开始. */ if (pageNo >= 1) { /* 提交的是下一页. */ firstResult = (pageNo - 1) * pageSize; /* 将从数据库中取出的职工信息存放在staffList中. */ List staffList = this.showStaffService.ShowStaff(firstResult, maxResult); request.setAttribute("staffList", staffList); /* 当前页,放到内置对象里,前台要用到. */ request.setAttribute("pageNo", pageNo); } /* 前台要显示总页数和当前页. */ request.setAttribute("totalPage", totalPage); return mapping.findForward("success"); // TODO Auto-generated method stub }}
2.在有flexgrid的页面中这样写:
//flaxgrid上的按钮的处理函数,分页等 function test1(data){ //alert('my' + data); if(data == 'Next') { $("#staffForm").attr("action","ShowStaffAction.do?buttonstate=Next&pageNo=${pageNo+1}"); //找到staffForm对应的form表单,并设置它的action属性为删除的action $("#staffForm").submit(); //提交操作 } if(data == 'Reload') { $("#staffForm").attr("action","ShowStaffAction.do?buttonstate=Reload&pageNo=${pageNo}"); //找到staffForm对应的form表单,并设置它的action属性为删除的action $("#staffForm").submit(); //提交操作 } if(data == 'Prev') { $("#staffForm").attr("action","ShowStaffAction.do?buttonstate=Prev&pageNo=${pageNo-1}"); //找到staffForm对应的form表单,并设置它的action属性为删除的action $("#staffForm").submit(); //提交操作 } if(data == 'First') { $("#staffForm").attr("action","ShowStaffAction.do?buttonstate=First&pageNo=${pageNo-1}"); //找到staffForm对应的form表单,并设置它的action属性为删除的action $("#staffForm").submit(); //提交操作 } if(data == 'Last') { $("#staffForm").attr("action","ShowStaffAction.do?buttonstate=Last&pageNo=${pageNo+1}"); //找到staffForm对应的form表单,并设置它的action属性为删除的action $("#staffForm").submit(); //提交操作 } }
3.在业务层Dao这样写:
package com.hithd.iswmanagement.DaosImpl;import java.util.List;import org.springframework.orm.hibernate3.support.HibernateDaoSupport;import com.hithd.iswmanagement.Daos.ShowStaffDao;public class ShowStaffDaoImpl extends HibernateDaoSupport implements ShowStaffDao { public List ShowStaff(int firstResult, int maxResult) {/* 用Query接口实现查询,并把所有数据存到一个LIST中. */ List staffList = this.getSession().createQuery("from StaffInformation") .setFirstResult(firstResult).setMaxResults(maxResult).list(); return staffList; // TODO Auto-generated method stub } public List ShowAllStaff() { List allstaffList = this.getSession().createQuery( "from StaffInformation").list(); return allstaffList; }}
4.分页效果:
- Hibernate和jQuery插件flexgrid集成分页
- Jquery表格插件flexgrid使用心得
- javascript-jquery插件--FlexGrid 用法参数
- Jquery flexgrid
- flexgrid jquery
- Jquery FlexGrid
- spring boot和mybatis集成分页插件
- 精品 jQuery Ajax 分页插件和教程
- Jquery Flexgrid 設定檔說明
- jquery分页插件
- jquery滚动分页插件
- myPagination Jquery 分页 插件
- myPagination Jquery 分页 插件
- jQuery分页插件jPage
- jQuery 分页插件 pagination
- jQuery分页小插件
- jQuery 分页插件
- jQuery分页插件
- Java 多线程编程之五:一个理解 wait() 与 notify() 的例子
- 如何将MFC程序改为UNICODE类型
- arm笔记2-arm嵌入式系统实验教程(3)实验2.24
- HDU 2050 折线拆分平面
- 是什么掐住了手机视频的咽喉
- Hibernate和jQuery插件flexgrid集成分页
- flex4图片教程[续]
- POJ 2488
- JS代码中实现IFrame内外页面的互访问
- 剖析SQLSERVER2005的页面结构--表修改的内部处理篇
- PAZU -- 4Fang WEB 打印控件
- 最欠缺的
- 典型的SQL语句
- select 和 epoll比较