page类:
package com.qst.model;
public class Page {
public int PAGESIZE=5;
//SqlSession session=MyBatisDBUtil.getSession();
int nowpage=1;
int maxpage=0;
int minpage=0;
int gopage=1;
int nextpage=0;
int purepage=0;
int count=0;
int pageSum=0;
/**
* @return Returns the pAGESIZE.
*/
public int getPAGESIZE() {
return PAGESIZE;
}
/**
* @param pAGESIZE The pAGESIZE to set.
*/
public void setPAGESIZE(int pAGESIZE) {
PAGESIZE = pAGESIZE;
}
public int getPageSum() {
if(this.getCount()%PAGESIZE==0){
return this.getCount()/PAGESIZE;
}
else{
return this.getCount()/PAGESIZE+1;
}
}
public void setPageSum(int pageSum) {
this.pageSum = pageSum;
}
public int getGopage() {
return gopage;
}
public void setGopage(int gopage) {
if(gopage>this.getPageSum()){
this.gopage=this.getPageSum();
this.nowpage=this.gopage;
System.out.println("第"+this.gopage+"页");
}
else{
this.gopage = gopage;
this.nowpage=this.gopage;
System.out.println("this.gopage"+this.gopage);
}
}
public int getCount() {
return count;
}
public void setCount(int count) {
this.count = count;
}
public int getNowpage() {
return nowpage;
}
public void setNowpage(int nowpage) {
this.nowpage = nowpage;
}
public int getMaxpage() {
return gopage*PAGESIZE;
}
public void setMaxpage(int maxpage) {
this.maxpage = maxpage;
}
public int getMinpage() {
return (gopage-1)*PAGESIZE+1;
}
public void setMinpage(int minpage) {
this.minpage = minpage;
}
public int getNextpage() {
return this.nowpage+1;
}
public void setNextpage(int nextpage) {
this.nextpage = nextpage;
}
public int getPurepage() {
if((this.nowpage-1)==0){
return 1;
}
else{
return this.nowpage-1;
}
}
public void setPurepage(int purepage) {
this.purepage = purepage;
}
}
Servlet实现:
if("chanceList".equals(flag)){
String s_gopage = request.getParameter("gopage");// 接收pageNow参数
int gopage = 1;
int PAGESIZE=5;//定义,初始化当前页数
/*
* 判断 s_pageNow是否为空
*/
if (s_gopage != null) {
gopage = Integer.parseInt(s_gopage);
}
String s_PAGESIZE=request.getParameter("PAGESIZE");
if(s_PAGESIZE!=null){
PAGESIZE=Integer.parseInt(s_PAGESIZE);
}
Map<String,Object> map=new HashMap<String,Object>();
page=new Page();
page.setPAGESIZE(PAGESIZE);
page.setCount(chanceService.selectList().size());//总行数
page.setGopage(gopage);
map.put("page",page);
List<Chance> listPage=chanceService.listPage(map);
request.setAttribute("list", listPage);
request.setAttribute("page", page);
request.getRequestDispatcher("html/~sale/list.jsp").forward(request, response);
myBatis Mapper:
<select id="listPage" parameterType="Map" resultType="Chance">
select * from (select a.*,rownum rn from (
select
chc_id,
chc_source,
chc_cust_name,
chc_title,
chc_rate,
chc_linkman,
chc_tel,
chc_desc,
chc_create_id,
chc_due_date,
chc_status
from sys_chance
order by chc_id
) a where rownum <= #{page.maxpage}) where rn >= #{page.minpage}
</select>