【java基础】jdbc的简单分页查询
2017-04-12 23:10
465 查看
1.创建分页实体类
public class PageBean<T> {
private List<T> list;// 当前页内容 查询
private int currPage;// 当前页码 传递
private int pageSize;// 每页显示的条数 固定
private int totalCount;// 总条数 查询
private int totalPage;// 总页数 计算
。。。。。
/**
* 获取总页数
*
* @return
*/
public int getTotalPage() {
return (int) Math.ceil(totalCount * 1.0 / pageSize);
}
public PageBean() {
}
public PageBean(List<T> list, int currPage, int pageSize, int totalCount) {
super();
this.list = list;
this.currPage = currPage;
this.pageSize = pageSize;
this.totalCount = totalCount;
}
}
2.service调Dao分别获取查询当页的数据list和总数count
将list和count等数据封装到PageBean中
3.servlet通过service获取数据返回到前台展示
分页部分:
<center>
<!-- 若是第一页,首页和上一页不显示 -->
<c:if test="${pb.currPage!=1 }">
<a
href="${pageContext.request.contextPath }/showProductsByPage?currPage=1">[首页]</a>
<a
href="${pageContext.request.contextPath }/showProductsByPage?currPage=${pb.currPage-1}">[上一页]</a>
</c:if>
<!-- 将所有的页码显示出来 -->
<c:forEach begin="1" end="${pb.totalPage }" var="n">
<c:if test="${pb.currPage==n }">
${n }
</c:if>
<c:if test="${pb.currPage!=n }">
<a
href="${pageContext.request.contextPath }/showProductsByPage?currPage=${pb.currPage}">${n }</a>
</c:if>
</c:forEach>
<!-- 若是最后一页,末页和下一页不显示 -->
<c:if test="${pb.currPage!=pb.totalPage }">
<a
href="${pageContext.request.contextPath }/showProductsByPage?currPage=${pb.currPage+1}">[下一页]</a>
<a
href="${pageContext.request.contextPath }/showProductsByPage?currPage=${pb.totalPage}">[末页]</a>
</c:if>
</center>
public class PageBean<T> {
private List<T> list;// 当前页内容 查询
private int currPage;// 当前页码 传递
private int pageSize;// 每页显示的条数 固定
private int totalCount;// 总条数 查询
private int totalPage;// 总页数 计算
。。。。。
/**
* 获取总页数
*
* @return
*/
public int getTotalPage() {
return (int) Math.ceil(totalCount * 1.0 / pageSize);
}
public PageBean() {
}
public PageBean(List<T> list, int currPage, int pageSize, int totalCount) {
super();
this.list = list;
this.currPage = currPage;
this.pageSize = pageSize;
this.totalCount = totalCount;
}
}
2.service调Dao分别获取查询当页的数据list和总数count
将list和count等数据封装到PageBean中
3.servlet通过service获取数据返回到前台展示
分页部分:
<center>
<!-- 若是第一页,首页和上一页不显示 -->
<c:if test="${pb.currPage!=1 }">
<a
href="${pageContext.request.contextPath }/showProductsByPage?currPage=1">[首页]</a>
<a
href="${pageContext.request.contextPath }/showProductsByPage?currPage=${pb.currPage-1}">[上一页]</a>
</c:if>
<!-- 将所有的页码显示出来 -->
<c:forEach begin="1" end="${pb.totalPage }" var="n">
<c:if test="${pb.currPage==n }">
${n }
</c:if>
<c:if test="${pb.currPage!=n }">
<a
href="${pageContext.request.contextPath }/showProductsByPage?currPage=${pb.currPage}">${n }</a>
</c:if>
</c:forEach>
<!-- 若是最后一页,末页和下一页不显示 -->
<c:if test="${pb.currPage!=pb.totalPage }">
<a
href="${pageContext.request.contextPath }/showProductsByPage?currPage=${pb.currPage+1}">[下一页]</a>
<a
href="${pageContext.request.contextPath }/showProductsByPage?currPage=${pb.totalPage}">[末页]</a>
</c:if>
</center>
相关文章推荐
- java自学之路-----jdbc_分页查询,大数据,批处理,存储过程
- [疯狂Java]JDBC:ResultSet的升级RowSet、离线的CachedRowSet、离线分页查询
- 【javaJDBC基础】【简单的入门语句代码】
- 简单分页查询(web基础学习笔记十三)
- JAVA之Mybatis基础入门--框架搭建与简单查询
- 【java基础】一个简单的学生寝室查询系统
- Java_jdbc 基础笔记之九 数据库连接 (查询Customer对象的方法)
- [疯狂Java]JDBC:ResultSet的升级RowSet、离线的CachedRowSet、离线分页查询
- java-JDBC简单的利用存储过程来《查询》或者《插入》
- java使用jdbc查询mysql数据最简单的例子
- Java_jdbc 基础笔记之十一数据库连接 (通用的查询方法)
- JavaWeb基础+oracle实现简单简单分页商品浏览与加入购物车系统
- java简单实现分页查询
- Java实现简单分页查询显示
- JAVA基础之JDBC开发、JSTL语法、EL表达式与数据分页
- JavaWeb基础-分页查询
- java简单jdbc查询操作
- Java与Struts结合写一个简单基础的分页显示
- Java_jdbc 基础笔记之八 数据库连接(写一个查询Student对象的方法)
- Java Jdbc 连接 Oracle 执行简单查询示例