DAO层
/**
* 分页查询全部员工,获取总记录数
*/
public int totalPage(String className);
/**
* 分页查看,查看首页
*/
public List<Employee> selectByPage(String className,int pageNo,int pageSize);

  DaoImp里面

 private EmployeeDao employeeDao;

    public void setEmployeeDao(EmployeeDao employeeDao) {
this.employeeDao = employeeDao;
} /**
* 员工列表分页查询,查询总页数
* @param className
* @return
*/
@Override
public int totalPage(String className) {
String hql="select count(*) from "+className;
Query query= this.getSession().createQuery(hql);
int total=Integer.parseInt(query.list().get(0).toString());
return total;
} /**
* 分页查询,查询首页
* @param className
* @param pageNo
* @param pageSize
* @return
*/
@SuppressWarnings("unchecked")
@Override
public List<Employee> selectByPage(String className, int pageNo, int pageSize) {
Query query=this.getSession().createQuery("from "+className);
query.setFirstResult((pageNo-1)*pageSize);//每页显示的第一条记录
query.setMaxResults(pageSize);//每页显示的记录数
return query.list();
}

  BIz层

 /**
* 分页查看,查看首页
*/
@SuppressWarnings("rawtypes")
public List<Employee> selectByPage(String className,int pageNo,int pageSize); /**
* 查看下一页
* @param line
* @param className
* @return
*/
public int searchRecordsNextPage(int line,String className);

  BIzImpl层

    private EmployeeDao employeeDao;

    public void setEmployeeDao(EmployeeDao employeeDao) {
this.employeeDao = employeeDao;
} /**
* 分页查询
* @param className
* @param pageNo
* @param pageSize
* @return
*/
@SuppressWarnings("rawtypes")
@Override
public List<Employee> selectByPage(String className, int pageNo, int pageSize) {
List list= employeeDao.selectByPage(className,pageNo,pageSize);
return list;
} /**
* 查看下一页
* @param pageSize
* @param className
* @return
*/
@Override
public int searchRecordsNextPage(int pageSize, String className) {
int total = employeeDao.totalPage(className);
int pageNo = total / pageSize;
if(total % pageSize>0){
pageNo++;
}
return pageNo;
}

  Action控制层

private Employee employee=new Employee();
@Override
public Employee getModel() {
return employee;
}
private EmployeeBiz employeeBiz; public void setEmployeeBiz(EmployeeBiz employeeBiz) {
this.employeeBiz = employeeBiz;
} /**
* 分页查看员工列表
*/
@SuppressWarnings({"unchecked","rawtypes"})
public String selectFirstPage(){
Map<String,Object> request= (Map<String, Object>) ActionContext.getContext().get("request");
try{
List list=employeeBiz.selectByPage("Employee",1,3);
int totalPage=employeeBiz.searchRecordsNextPage(3,"Employee");
request.put("list",list);
request.put("totalPage",totalPage);
request.put("currentPage",1);
}catch(Exception e){
e.printStackTrace();
}
return "selectFirstPage";
}
/**
* 分页查找下一页
*/
@SuppressWarnings("rawtypes")
public String selectNextPage(){
HttpServletRequest request= ServletActionContext.getRequest();
int next=Integer.parseInt(request.getParameter("page"));
try{
List list=employeeBiz.selectByPage("Employee",next,3);
int total=employeeBiz.searchRecordsNextPage(3,"Employee");
request.setAttribute("list",list);
request.setAttribute("currentPage",next);
request.setAttribute("totalPage",total);
}catch(Exception e){
e.printStackTrace();
}
return "selectNextPage";
}

  前端div接收参数

<div>
第${currentPage }页
<input type="hidden" id="tpage" name="tpage"
value="${totalPage} "></input>
<c:if test="${currentPage>1 }">
<input type="button" value="首页" onclick="show(1)"></input>
<input type="button" value="上一页" onclick="show(${currentPage-1})"></input>
</c:if>
<c:if test="${currentPage<totalPage }">
<input type="button" value="下一页" onclick="show(${currentPage+1},${totalPage })"></input>
<input type="button" value="尾页" onclick="show(${totalPage})"></input>
</c:if>
共${totalPage }页
</div>
</div>

  前端javascript里

 function show(next,total){
if (next<=0) {
alert("已经是首页了");
return;
}
if (next>total) {
alert("已经是尾页了");
return;
}
document.forms[0].action="employeeselectNextPage?page="+next;
document.forms[0].submit();
}

  注意:1,在body里面要想实现分页要把body里面的form表单加上

<form id="myForm" name="myForm" method="post">

2,如果使用的是mysql需要修改hibernate.cfg.xml里面的

<property name="dialect">org.hibernate.dialect.MySQLDialect</property>

  3,在struts.xml文件里面需要修改name里面的是第一页和下一页的方法

<!-- Employee action -->
<action name="employee*" class="EmployeeAction" method="{1}">
<result name="selectFirstPage">/employee.jsp</result>
<result name="selectNextPage">/employee.jsp</result>
<result name="add" type="redirectAction">employeeselectFirstPage</result>
<result name="updateEmp">/employee_update.jsp</result>
<result name="update" type="redirectAction">employeeselectFirstPage</result>
<result name="delete" type="redirectAction">employeeselectFirstPage</result>
<result name="error">/error.jsp</result>
</action>

 

SSH框架分页的更多相关文章

  1. 分页技术框架(Pager-taglib)学习二(SSH数据库分页)

    一.Pager-taglib数据库分页前提    Pager-taglib分页标签也可以实现数据库分页,与页面分页不同的是需要给后台传两个参数,一个是pageNo(当前页数)或pageOffset(偏 ...

  2. 使用maven搭建SSH框架实现登陆、列表查询分页

    SSH框架:struts2 + spring + hibernate web层:struts2+jsp service层:javaBean dao层:hibernate spring:管理Action ...

  3. 管理系统-------------SSH框架书写登录和显示用户

    一.思路的穿插. web.xml中的配置找到--->application.xml---->找到对应的Action---->找到struts.xml----->在去找actio ...

  4. 学习SSH框架

    1.SSH框架的认知 在做相关的java的网页的开发制作时,良好的层次分解是十分有比要的,所以我们在云涌第三方的框架之下来简化还有名了我们相关的网站的开发. SSH框架实则为Struct + spri ...

  5. 项目分享:通过使用SSH框架的公司-学员关系管理系统(CRM)

    ----------------------------------------------------------------------------------------------[版权申明: ...

  6. 项目:《ssh框架综合项目开发视频》-视频目录和第六天的EasyUI简单讲解

    4 练习使用技术: Struts2 + hibernate5.x + spring4.x + mysql数据库 1 crm:customer relational manager,客户关系管理 2 c ...

  7. SSH框架结合案例构建配置

    ssh框架概述 SSH是 struts+spring+hibernate的一个集成框架,是目前比较流行的一种Web应用程序开源框架.区别于 Secure Shell . 集成SSH框架的系统从职责上分 ...

  8. 简化SSH框架的整合

    一.开发环境: (1)    OS:Windows 7 (2)    DB:MySql 5.1.6 (3)    JDK:1.8.0_17 (4)    Server:Apache Tomcat 8. ...

  9. SSH框架整合

    SSH框架整合 一.原理图 action:(struts2) 1.获取表单的数据 2.表单的验证,例如非空验证,email验证等 3.调用service,并把数据传递给service Service: ...

随机推荐

  1. Global.asax

    ASP.NET Global.asax 文件使用方法 - .net 标签:               asp.net.netapplicationauthenticationsessionobjec ...

  2. linux查看与修改交换内存配置(解决zabbix-agent启动报错)

    问题 zabbix-agent在一台centos6.5上启动报错: cannot allocate shared memory of size 949056: [28] No space left o ...

  3. P4114 Qtree1

    思路 树剖一发,注意对LCA的处理 代码 #include <cstdio> #include <algorithm> #include <cstring> usi ...

  4. 移动web开发中input等输入框问题

    移动端web开发时,input等输入框在安卓和iso中都有问题,分别有:1.iso不能点击其他区域使得输入框失去焦点2.iso输入框失去焦点后,键盘产生的空白部分不消失3.安卓端输入框得到焦点后,输入 ...

  5. js 空语句

    不写就行了 ){}

  6. .net扩展方法

    http://www.cnblogs.com/landeanfen/p/4632467.html 看了博客才知道定义一个Util工具类并且在工具类里面写静态扩展方法并不是最好的选择.

  7. 在阿里云开源镜像站中下载centOS7

    镜像的选择 第一步.下载镜像 阿里云开源镜像站:http://mirrors.aliyun.com/ 选择centos进入 如下图: 如下图:选择centos7 再选择isos(镜像目录) 继续下一步 ...

  8. 给echart初始化的dom节点绑定时间获取点击的值渲染省市区

    this.drawMap().on('click', function (params) { var province = params.name; that.mapStatus = province ...

  9. scrapyd的安装和scrapyd-client

    1.创建虚拟环境  ,虚拟环境名为sd mkvirtualenv sd #方便管理 2. 安装 scrapyd pip3 install scrapyd 3. 配置 mkdir /etc/scrapy ...

  10. Vue之添加全局变量

    定义全局变量 原理: 设置一个专用的的全局变量模块文件,模块里面定义一些变量初始状态,用export default 暴露出去,在main.js里面使用Vue.prototype挂载到vue实例上面或 ...