java实实现现分分页页显显示示效效果果
本文实例为大家分享了java实现页显示效果的具体代码,供大家参考,具体内容如下
效效果果图图如如下下::
实实现现 骤骤::
1.创建实体User.class,参考代码如下:
public class User {
private String name;
private int age;
private String gender;
public String getName() {
return name;
}
public void setName(String name) {
= name;
}
public int getAge() {
return age;
}
public void setAge(int age) {
this.age = age;
}
public String getGender() {
return gender;
}
public void setGender(String gender) {
this.gender = gender;
}
public User(String name int age String gender) {
super();
= name;
this.age = age;
this.gender = gender;
}
public User() {
}
}
2.创建分页模型PageBean.class,参考代码如下:
public class PageBean {
private int pageNum;
private int pageSize;
private int totalRecord;
private int totalPage;
private List list;
private int start;
private int end;
private int fromIndex;
private int toIndex;
public PageBean(int pageNum int pageSize int totalRecord) {
this.pageNum = pageNum;
this.pageSize = pageSize;
this.totalRecord = totalRecord;
fromIndex=(pageNum-1)*pageSize;
toIndex=pageNum*pageSize>totalRecord?totalRecord:pageNum*pageSize;
if (totalRecord % pageSize == 0) {
this.totalPage = totalRecord / pageSize;
} else {
this.totalPage = totalRecord / pageSize + 1;
}
start = 1;
end = 5;
if (totalPage <= 5) {
end = this.totalPage;
} else {
start = pageNum - 2;
end = pa