📄 mysqlpage.java
字号:
package com.mgie.pkmm.util.mysqlPage;
/**
* @作者 MG-小华仔 Mysql 分页bean
* This page is pagination like 当前页数:page/总页数:totalpage <<上一页|下一页>> 跳转到第 jumpPage页
*/
public class MysqlPage implements MysqlPageImp {
int per_page = 10; // 每页显示的数量
int total_page = 0;// 总页数
int page = 0; // 当前页数
boolean hasNextPage = false; // 是否有下一页
boolean hasPreviousPage = false; // 是否有前一页
int start_num = 0; //The start row number in mysql
String actionLink="";
public String getActionLink() {
return actionLink;
}
public void setActionLink(String actionLink) {
this.actionLink = actionLink;
}
// ====================Init()=============================
public MysqlPage() {
per_page = 10;
total_page = 0;
page = 0;
hasNextPage = false;
hasPreviousPage = false;
start_num = 0;
}
/***************************************************************************
*
* @param total_page
* @param start_num
* @param per_page
*
* eg:select * from table limit start_num,perpage
*/
public MysqlPage(int total_page, int per_page,String actionLink) {
if (total_page % per_page == 0)
this.total_page = total_page / per_page;
else
this.total_page = total_page / per_page + 1;
this.per_page = per_page;
this.actionLink = actionLink;
}
// ================================================================
public int getPage() {
return page+1;
}
public void setPage(int page) {
this.page = page;
}
public int getPer_page() {
return per_page;
}
public void setPer_page(int per_page) {
this.per_page = per_page;
}
public int getTotal_page() {
return total_page;
}
public void setTotal_page(int total_page) {
this.total_page = total_page;
}
public int getStart_num() {
start_num = (page * per_page);
return start_num;
}
public void setStart_num(int start_num) {
this.start_num = start_num;
}
public boolean isHasNextPage() {
if (page + 1 < total_page)
hasNextPage = true;
else
hasNextPage = false;
return hasNextPage;
}
public void setHasNextPage(boolean hasNextPage) {
this.hasNextPage = hasNextPage;
}
public boolean isHasPreviousPage() {
if (page - 1 >= 0)
hasPreviousPage = true;
else
hasPreviousPage = false;
return hasPreviousPage;
}
public void setHasPreviousPage(boolean hasPreviousPage) {
this.hasPreviousPage = hasPreviousPage;
}
/***=========================Contorl part =========================****/
/**
* 初始化
* @param total_page
* @param start_num
* @param per_page
*/
public void init(int total_page,int per_page,String actionLink) {
if (total_page % per_page == 0)
this.total_page = total_page / per_page;
else
this.total_page = total_page / per_page + 1;
this.per_page = per_page;
this.actionLink = actionLink;
}
public void nextPage() {
page++;
if (page + 1 > total_page) {
page = total_page - 1;
hasNextPage = false;
}
}
public void prvPage() {
page--;
if (page < 0) {
page = 0;
hasPreviousPage = false;
}
}
public void jumpPage(int jump_page) {
if (jump_page < 0) {
page = 0;
hasPreviousPage = false;
}
else if (jump_page > total_page) {
page = total_page - 1;
hasNextPage = false;
} else {
page = jump_page - 1;
}
}
/* public boolean isLastpage() {
if (page == total_page - 1) {
hasNextPage = false;
return true;
} else
return false;
}
*/
public void description() {
String description =
"共有页数: " + this.getTotal_page() +
"当前页数为:" + this.getPage() +
" 是否有前一页: " + this.isHasPreviousPage() +
" 是否有下一页:" + this.isHasNextPage() +
" 开始行数:" + this.getStart_num();
}
public String getLinkcode() {
// TODO Auto-generated method stub
String code="当前第"+this.getPage()+"页/总共 "+this.getTotal_page()+"页 ";
String prvpageLink="<上一页";
String prvlinkString="<a href='"+actionLink+"&action=prvPage'><上一页</a>";
String nextpageLink="下一页>";
String nextlinkString="<a href='"+actionLink+"&action=nextPage'>下一页></a>";
String javascript="<script>function jump(){var a= document.getElementById('jumpBox').value;window.location='"+actionLink+"&action=jumpPage&jumpPage='+a;}</script>";
String inputBox="<input type='text' id='jumpBox' name='jumpBox' value=0 onpropertychange="+'"'+"if(/\\D/g.test(value))value=value.replace(/\\D/g,'')"+'"' +"style='ime-mode:disabled' ondragenter='return false' maxlength=9 size=9>";
String jumpBt="<input type='button' name='jumpBt' value='跳转' onclick='jump()'>";
if (this.isHasPreviousPage())
{
prvpageLink=prvlinkString;
}
if(this.isHasNextPage())
{
nextpageLink=nextlinkString;
}
code =code+ prvpageLink+" "+nextpageLink+" "+inputBox+" "+jumpBt+javascript;
return code;
}
}
/***
* //===========================Page list use like this:==================================
String action =String.valueOf(request.getParameter("action"));
if(request.getParameter("action")==null)
{
int total = skinDao.countSkin();
mp = new MysqlPage(total,per_page);
}
else
{
if(request.getParameter("jumpPage")!=null)
mp.jumpPage(Integer.parseInt(request.getParameter("jumpPage")));
else
{
if(action.equals("nextPage"))
mp.nextPage();
else
mp.prvPage();
}
}
request.setAttribute("mysqlpage", mp);
*/
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -