SSH框架分页
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框架分页的更多相关文章
- 分页技术框架(Pager-taglib)学习二(SSH数据库分页)
一.Pager-taglib数据库分页前提 Pager-taglib分页标签也可以实现数据库分页,与页面分页不同的是需要给后台传两个参数,一个是pageNo(当前页数)或pageOffset(偏 ...
- 使用maven搭建SSH框架实现登陆、列表查询分页
SSH框架:struts2 + spring + hibernate web层:struts2+jsp service层:javaBean dao层:hibernate spring:管理Action ...
- 管理系统-------------SSH框架书写登录和显示用户
一.思路的穿插. web.xml中的配置找到--->application.xml---->找到对应的Action---->找到struts.xml----->在去找actio ...
- 学习SSH框架
1.SSH框架的认知 在做相关的java的网页的开发制作时,良好的层次分解是十分有比要的,所以我们在云涌第三方的框架之下来简化还有名了我们相关的网站的开发. SSH框架实则为Struct + spri ...
- 项目分享:通过使用SSH框架的公司-学员关系管理系统(CRM)
----------------------------------------------------------------------------------------------[版权申明: ...
- 项目:《ssh框架综合项目开发视频》-视频目录和第六天的EasyUI简单讲解
4 练习使用技术: Struts2 + hibernate5.x + spring4.x + mysql数据库 1 crm:customer relational manager,客户关系管理 2 c ...
- SSH框架结合案例构建配置
ssh框架概述 SSH是 struts+spring+hibernate的一个集成框架,是目前比较流行的一种Web应用程序开源框架.区别于 Secure Shell . 集成SSH框架的系统从职责上分 ...
- 简化SSH框架的整合
一.开发环境: (1) OS:Windows 7 (2) DB:MySql 5.1.6 (3) JDK:1.8.0_17 (4) Server:Apache Tomcat 8. ...
- SSH框架整合
SSH框架整合 一.原理图 action:(struts2) 1.获取表单的数据 2.表单的验证,例如非空验证,email验证等 3.调用service,并把数据传递给service Service: ...
随机推荐
- nodejs笔记之连接mysql数据库
1.安装mysql模块: npm install mysql 2.引入mysql模块 创建一个server.js文件 const http = require("http"); c ...
- react初始
一.一些基础概念 1.框架:基于整个项目的 2.库:在某个模块中单独使用,轻量级的 在vue中,DOM的操作时DOM指令调用js 在react中,所有的DOM 渲染都是由JS完成的 组件基于视图 模块 ...
- 利用phpspider爬取网站数据
本文实例原址:PHPspider爬虫10分钟快速教程 在我们的工作中可能会涉及到要到其它网站去进行数据爬取的情况,我们这里使用phpspider这个插件来进行功能实现. 1.首先,我们需要php环境, ...
- 不错的anroid源码在线浏览网站【学习笔记】
不错的anroid源码在线浏览网站:http://androidxref.com/
- Python连接MySQL数据库之pymysql模块
pymysql 在python3.x 中用于连接MySQL服务器的一个库:Python2中则使用mysqldb pymysql的模块的基本的使用 # 导入pymysql模块 import pymysq ...
- IIC为什么要配置为开漏输出呢?
开漏输出只能输出低电平,类似于三极管的集电极,要输出高电平需要上拉电阻才能输出 当集电极接上拉电阻后,(1)基极为高电平,三极管导通,集电极的电位就会被拉低: (2)基极为低电平,三极管不导通,集电极 ...
- python程序—用户登录
编写一个用户登录程序: 1.登录成功显示登录页面 2.登录失败,显示密码错误,并且显示错误几次 3.登录失败三次,退出程序 username= 'root' passwd= ' count= prin ...
- git误commit大文件导致不能push问题解决
git push时终端报错: error: RPC failed; HTTP 413 curl 22 The requested URL returned error: 413 Request Ent ...
- Ubuntu下的Selenium爬虫的配置
在服务器Ubuntu系统上跑爬虫,爬虫是基于Selenium写的,遇到好几个问题,现在这里记录一下. 1. 安装环境 阿里云,Ubuntu16.04,因为没有界面,所以远程命令行操作.爬虫是基于Sel ...
- 第二章 Java 基本语法1
2.1关键字 1.定义:被Java语言赋予了特殊含义,用做专门用途的字符串(单词). 2.特点:关键字中所有字母都是小写字母. 3.分类: 用于定义数据类型的关键字:byte.short.int.lo ...