JavaWeb--简单分页技术
时间:2022-07-26
本文章向大家介绍JavaWeb--简单分页技术,主要内容包括其使用实例、应用技巧、基本知识点总结和需要注意事项,具有一定的参考价值,需要的朋友可以参考一下。
分页需要的技术点:1.前台分页标签的使用
2.前台上一页,下一页显示的业务逻辑
3.MSQL用到的语句 limit
4.封装pageBean对象
这个是PageBean用到的
分页公式:
- int totalPageNum = (totalRecord + pageSize - 1) / pageSize;
package com.itheima.vo;
import java.util.ArrayList;
import java.util.List;
import com.itheima.domain.Product;
public class PageBean<T> {
//当前页
private int currentPage;
//当前页显示的条数
private int currentCount;
//总条数
private int totalCount;
//总页数
private int totalPage;
//每页显示的数据
private List<T> productList = new ArrayList<T>();
public int getCurrentPage() {
return currentPage;
}
public void setCurrentPage(int currentPage) {
this.currentPage = currentPage;
}
public int getCurrentCount() {
return currentCount;
}
public void setCurrentCount(int currentCount) {
this.currentCount = currentCount;
}
public int getTotalCount() {
return totalCount;
}
public void setTotalCount(int totalCount) {
this.totalCount = totalCount;
}
public int getTotalPage() {
return totalPage;
}
public void setTotalPage(int totalPage) {
this.totalPage = totalPage;
}
public List<T> getProductList() {
return productList;
}
public void setProductList(List<T> productList) {
this.productList = productList;
}
}
前台页面上的分页标签显示逻辑
<!--分页 -->
<div style="width: 380px; margin: 0 auto; margin-top: 50px;">
<ul class="pagination" style="text-align: center; margin-top: 10px;">
<!-- 上一页 -->
<!-- 判断当前页是否是第一页 -->
<c:if test="${pageBean.currentPage==1 }">
<li class="disabled">
<a href="javascript:void(0);" aria-label="Previous">
<span aria-hidden="true">«</span>
</a>
</li>
</c:if>
<c:if test="${pageBean.currentPage!=1 }">
<li>
<a href="${pageContext.request.contextPath }/productList?currentPage=${pageBean.currentPage-1}" aria-label="Previous">
<span aria-hidden="true">«</span>
</a>
</li>
</c:if>
<c:forEach begin="1" end="${pageBean.totalPage }" var="page">
<!-- 判断当前页 -->
<c:if test="${pageBean.currentPage==page }">
<li class="active"><a href="javascript:void(0);">${page}</a></li>
</c:if>
<c:if test="${pageBean.currentPage!=page }">
<li><a href="${pageContext.request.contextPath }/productList?currentPage=${page}">${page}</a></li>
</c:if>
</c:forEach>
<!-- 判断当前页是否是最后一页 -->
<c:if test="${pageBean.currentPage==pageBean.totalPage }">
<li class="disabled">
<a href="javascript:void(0);" aria-label="Next">
<span aria-hidden="true">»</span>
</a>
</li>
</c:if>
<c:if test="${pageBean.currentPage!=pageBean.totalPage }">
<li>
<a href="${pageContext.request.contextPath }/productList?currentPage=${pageBean.currentPage+1}" aria-label="Next">
<span aria-hidden="true">»</span>
</a>
</li>
</c:if>
</ul>
</div>
<!-- 分页结束 -->
- java教程
- Java快速入门
- Java 开发环境配置
- Java基本语法
- Java 对象和类
- Java 基本数据类型
- Java 变量类型
- Java 修饰符
- Java 运算符
- Java 循环结构
- Java 分支结构
- Java Number类
- Java Character类
- Java String类
- Java StringBuffer和StringBuilder类
- Java 数组
- Java 日期时间
- Java 正则表达式
- Java 方法
- Java 流(Stream)、文件(File)和IO
- Java 异常处理
- Java 继承
- Java 重写(Override)与重载(Overload)
- Java 多态
- Java 抽象类
- Java 封装
- Java 接口
- Java 包(package)
- Java 数据结构
- Java 集合框架
- Java 泛型
- Java 序列化
- Java 网络编程
- Java 发送邮件
- Java 多线程编程
- Java Applet基础
- Java 文档注释