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. go语言开发教程之web项目开发实战

    Golang介绍Go语言是谷歌推出的一种全新的编程语言,可以在不损失应用程序性能的情况下降低代码的复杂性.谷歌首席软件工程师罗布派克(Rob Pike)说:我们之所以开发Go,是因为过去10多年间软件 ...

  2. docker tmpfs 的测试结果

    创建 2G 内存的 Container 使用tmpfs挂载到 /tmp docker run --rm -it --memory 2g --mount type=tmpfs,destination=/ ...

  3. 第十六节 BOM基础

    打开.关闭窗口 open:蓝色理想运行代码功能 <button onclick="window.open('http://www.baidu.com')">打开窗口&l ...

  4. python 字典嵌套字典赋值异常

    针对dict中 嵌套dict 出现复制异常 lists={} test=['s1','s2','s3'] data = {'value': '',} for i in range(2): lists[ ...

  5. MySQL中show profiles的开启

    Query Profiler是MYSQL自带的一种query诊断分析工具,通过它可以分析出一条SQL语句的性能瓶颈在什么地方.通常我们是使用的explain,以及slow query log都无法做到 ...

  6. iOS 开发 Tips

    1.MVVM 的优点 MVVM 兼容 MVC,可以先创建一个简单的 View Model,再慢慢迁移. MVVM 使得 app 更容易测试,因为 View Model 部分不涉及 UI. MVVM 最 ...

  7. 软考自查:数据流图(DFD)

    数据流图(DFD) 内容提要 数据流图基本概念 数据字典 数据平衡原则 数据流图基本概念             数据字典     数据流图平衡原则 父图与子图之间的平衡 子图内平衡         ...

  8. Jenkins学习

    1.jenkins启动卡在密码初始化处不动的情况,参照: https://blog.csdn.net/lylload/article/details/82754101 https://blog.csd ...

  9. P3321 [SDOI2015]序列统计

    思路 首先有个挺显然的DP \[ dp[i][(j*k)\%m]+=dp[i-1][j]\times dp[i-1][k] \] 想办法优化这个DP 这个dp也可以写成这样 \[ dp[i][j]=\ ...

  10. Ubuntu 远程 Jupyter 配置

    Ubuntu 远程 Jupyter 配置 每次上课都要重新部署环境,最近看到阿里云的大学生优惠活动,就着手了一台云服务器,于是就把环境部署在上面了. 环境:阿里云 Ubuntu 16.04 64位 新 ...