首页 > 代码库 > java 分页封装类

java 分页封装类

//后台Page.java
package com.complaints.util;5
import java.util.List;
import java.util.Map;
public class Page {
private String pageBar;
private int pageCount;//页总数
private int rowCount;//总行数
private int pagesize = 10;//每页显示的数据记录
private int curPage;//当前页
private int first;//首页
private int prev;//上一页
private int next;//下一页
private int last;//定义每一页的结束 end
private List<Map<String, Object>> list;//储存查询的结果集
public String getPageBar() {
return pageBar;
public void setPageBar(String pageBar) {
String str;
str = "<table cellpadding=‘0‘ cellspacing=‘0‘ width=‘100%‘>";
str+="<tr><td style=‘text-align: right;‘>共 ";
str+="<font color=‘red‘>"+this.getPageCount() +"</font> 页,";
str+="<font color=‘red‘>"+this.getRowCount() +" </font>条数据,";
str+="当前第 "+this.getCurPage()+" 页 ";
if(isFirst()){
str+="首页 上一页";
}else{
str+="<a href=‘javascript:page(1)‘>首页</a> <a href=‘javascript:page("+this.getPrev()+")‘>上一页</a>";
if(isLast()){
str+="下一页 末页";
}else{
str+="<a href=‘javascript:page("+this.getNext()+")‘>下一页</a> <a href=‘javascript:page("+this.getPageCount()+")‘>末页</a>";
this.pageBar = str;
public boolean isLast() {
return (this.getCurPage() == this.getPageCount()) ? true : false;
public boolean isFirst() {
return (this.getCurPage() == 1) ? true : false;
public int getFirst() {
this.first=1;
return first;
public void setFirst(int first) {
this.first = first;
public int getLast() {
this.last=(int) this.getPageCount();
return last;
public void setLast(int last) {
this.last = last;
public int getPageCount() {
this.pageCount= (int) Math.ceil((double) this.getRowCount()/(double) this.getPagesize());
return pageCount;
public void setPageCount(int pageCount) {
this.pageCount = pageCount;
public int getRowCount() {
return rowCount;
public void setRowCount(int rowCount) {
this.rowCount = rowCount;
public int getPagesize() {
return pagesize;
public void setPagesize(int pagesize) {
this.pagesize = pagesize;
public int getCurPage() {
return curPage==0?1:curPage;
public void setCurPage(int curPage) {
this.curPage = curPage;
public int getPrev() {
this.prev=(this.getCurPage()>1)?(this.getCurPage()-1):1;
return prev;
public void setPrev(int prev) {
this.prev = prev;
public int getNext() {
this.next=(this.getCurPage() < this.getPageCount()) ? (this.getCurPage()+1):this.getCurPage();
return next;
public void setNext(int next) {
this.next = next;
public List<Map<String, Object>> getList() {
return list;
public void setList(List<Map<String, Object>> list) {
this.list = list;
//action中引用
package com.complaints.web;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.ModelMap;
import org.springframework.web.bind.annotation.ModelAttribute;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.servlet.ModelAndView;
import com.complaints.po.User;
import com.complaints.service.UserService;
import com.complaints.util.Page;
@Controller
public class UserController {
@Autowiredhttp://www.huiyi8.com/jiaoben/
private UserService userservice; javascript特效
@RequestMapping("user/list")
public ModelAndView GetStateList(@ModelAttribute("user") User user,
@ModelAttribute("page") Page page){
page=userservice.listState(user, page);
page.setPageBar("");
ModelMap mp=new ModelMap();
mp.put("page",page);
ModelAndView mav = new ModelAndView("user/List_state",mp);
return mav;
//jsp页面引用
<script type="text/javascript">