实现步骤:
**
**
product模型类定义如下(根据自己的数据库而定)
**
package cn.jishupeng.bookstore.model;
public class Product {
private String id;
private String name;
private double price;
private String category;
private int pnum;
private String imgurl;
private String description;
public Product() {
}
public Product(String id, String name, double price, String category, int pnum, String imgurl, String description) {
this.id = id;
this.name = name;
this.price = price;
this.category = category;
this.pnum = pnum;
this.imgurl = imgurl;
this.description = description;
}
public String getId() {
return id;
}
public void setId(String id) {
this.id = id;
}
public String getName() {
return name;
}
public void setName(String name) {
this.name = name;
}
public double getPrice() {
return price;
}
public void setPrice(double price) {
this.price = price;
}
public String getCategory() {
return category;
}
public void setCategory(String category) {
this.category = category;
}
public int getPnum() {
return pnum;
}
public void setPnum(int pnum) {
this.pnum = pnum;
}
public String getImgurl() {
return imgurl;
}
public void setImgurl(String imgurl) {
this.imgurl = imgurl;
}
public String getDescription() {
return description;
}
public void setDescription(String description) {
this.description = description;
}
@Override
public String toString() {
return "Product{" +
"id='" + id + '\'' +
", name='" + name + '\'' +
", price=" + price +
", category='" + category + '\'' +
", pnum=" + pnum +
", imgurl='" + imgurl + '\'' +
", description='" + description + '\'' +
'}';
}
}
1 定义一个pageResult模型用于存储分页相关信息, 实现代码如下:
**
package cn.jishupeng.bookstore.model;
import java.util.List;
public class PageResult<T> {
List<T> list;
long totalCount;
int pageSize = 4;
int totalPage;
int currentPage;
public PageResult() {
}
public PageResult(List<T> list, long totalCount, int pageSize, int totalPage, int currentPage) {
this.list = list;
this.totalCount = totalCount;
this.pageSize = pageSize;
this.totalPage = totalPage;
this.currentPage = currentPage;
}
public List<T> getList() {
return list;
}
public void setList(List<T> list) {
this.list = list;
}
public long getTotalCount() {
return totalCount;
}
public void setTotalCount(long totalCount) {
this.totalCount = totalCount;
}
public int getPageSize() {
return pageSize;
}
public void setPageSize(int pageSize) {
this.pageSize = pageSize;
}
public int getTotalPage() {
return totalPage;
}
public void setTotalPage(int totalPage) {
this.totalPage = totalPage;
}
public int getCurrentPage() {
return currentPage;
}
public void setCurrentPage(int currentPage) {
this.currentPage = currentPage;
}
@Override
public String toString() {
return "PageResult{" +
"totalCount=" + totalCount +
", pageS