Javaweb-分页查询

使用Mysql的LIMIT方法实现分页查询

LIMIT查询方法

SELECT TABLE_COLUMN1,TABLE_COLUMN2...FROM TABLE_NAME LIMIT OFFSET rowNum;

分页的详细过程,以及分页所要涉及到的变量

  • 每一次都要查询总的数据量,防止在这一次查询的之前总的数据量发生了变化。
一、Entity层

Student.java

package com.zbt.entity;

public class Student {
    private int id;
    private String firstName;
    private String lastName;
    private String address;
    private String phone;
	
	public Student(){}
	
    public Student(int id,String firstName,String lastName,String address,String phone){
        this.id = id;
        this.firstName = firstName;
        this.lastName = lastName;
        this.address = address;
        this.phone = phone;
    }
    //省略了getters方法和setters方法
    @Override
    public String toString() {
        return "Student{" +
                "id=" + id +
                ", firstName='" + firstName + '\'' +
                ", lastName='" + lastName + '\'' +
                ", address='" + address + '\'' +
                ", phone='" + phone + '\'' +
                '}';
    }
}

Page对象:将一个页面信息全部封装到Page对象中

package com.zbt.entity;

import java.util.List;

public class Page {
    public final static int NUM = 5;
    private int start;//起始页
    private int next;//下一页
    private int last;//上一页
    private int currentPage;//当前页
    private int totalPage;//总页数
    private List<Student> studentList;//用户信息
	//构造方法
    public Page(){}
    public Page(int start,int num,List<Student> studentList){
        this.start = start;
        this.studentList = studentList;
        //caculate the last
        last = start == 0? start:start-NUM;
        // calculate the next
        next = start + NUM > num ? start: start+NUM;
        // calculate the currentPage
        currentPage = start/NUM +1;//start从零开始因此要加1
        //calculate the totalPage
        totalPage = num % NUM == 
评论 8
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值