public
class
PageBean {
publicint rowCount = 0;
publicint currentPage = 1;
publicint sizePerPage = 20;
publicint pageCount = 0;
publicString pageURL;
publicString pageDisplay;
publicString pageStyle =
"numberStyle"
;
publicint pagePreOffset = 10;
publicint pageNextOffset = 9;
publicString pageCss;
publicString getPageCss() {
returnpageCss;
}
publicvoid setPageCss(String pageCss) {
this.pageCss = pageCss;
}
publicString getPageStyle() {
returnpageStyle;
}
publicvoid setPageStyle(String pageStyle) {
this.pageStyle = pageStyle;
}
publicint getPagePreOffset() {
returnpagePreOffset;
}
publicvoid setPagePreOffset(intpagePreOffset) {
this.pagePreOffset = pagePreOffset;
}
publicint getPageNextOffset() {
returnpageNextOffset;
}
publicvoid setPageNextOffset(intpageNextOffset) {
this.pageNextOffset = pageNextOffset;
}
publicString getPageDisplay() {
String nextClick=
" onclick='ajaxpage("
"+this.pageURL+ "
?currentPage=
" + (this.currentPage + 1)+"
");return false;' "
;
String preClick=
" onclick='ajaxpage("
"+this.pageURL+ "
?currentPage=
" + (this.currentPage - 1)+"
");return false;' "
;
String firstClick=
" onclick='ajaxpage("
"+this.pageURL+ "
?currentPage=1
");return false;' "
;
String lastClick=
" onclick='ajaxpage("
"+this.pageURL+ "
?currentPage=
" + (this.getPageCount())+"
");return false;' "
;
String onChange=
" onchange='ajaxpage("
"+this.pageURL+ "
?currentPage=
" + (1)+"
");return false;' "
;
StringBuffer pageString =
new
StringBuffer();
pageString.append(
"<div class='"
+ this.pageStyle +
"'><span >"
);
if
(
"numberStyle"
.equalsIgnoreCase(this.pageStyle)) {
if
(this.getPageCount() ==1) {
}
else
{
if
(this.currentPage >1) {
pageString.append(
"<a class='pagination-first' "
+firstClick+
" title='首页' href='"
+ this.pageURL
+
"?currentPage=1'><<</a> "
);
pageString.append(
"<a class='pagination-prev' "
+preClick+
"title='上一页' href='"
+ this.pageURL
+
"?currentPage="
+ (this.currentPage -1)
+
"'><</a> "
);
}
else
{
pageString
.append(
"<a class='pagination-first'><<</a> "
);
pageString
.append(
"<a class='pagination-prev'><</a> "
);
}
intpreOffset = this.currentPage -1 > this.pagePreOffset ?this.pagePreOffset
:this.currentPage -1;
intnextOffset = this.getPageCount() -this.currentPage >this.pageNextOffset ?this.pageNextOffset
:this.getPageCount() -this.currentPage;
for
(int i = (this.currentPage - preOffset); i <= (this.currentPage + nextOffset); i++) {
String numClick=
" onclick='ajaxpage("
"+this.pageURL+ "
?currentPage=
" + (i)+"
");return false;' "
;
if
(this.currentPage == i) {
pageString
.append(
"<strong style='color:black;border:0'>"
+ i +
"</strong> "
);
}
else
{
pageString.append(
"<a "
+numClick+
"href='"
+ this.pageURL
+
"?currentPage="
+ i +
"'>"
+ i +
"</a> "
);
}
}
if
(this.currentPage <this.getPageCount()) {
pageString.append(
"<a class='pagination-next' "
+nextClick+
" title='下一页' href='"
+ this.pageURL
+
"?currentPage="
+ (this.currentPage +1)
+
"'>></a> "
);
pageString.append(
"<a class='pagination-last' "
+lastClick+
"title='尾页' href='"
+ this.pageURL
+
"?currentPage="
+ (this.getPageCount()) +
"'>>></a> "
);
}
else
{
pageString
.append(
"<a class='pagination-next' >></a> "
);
pageString
.append(
"<a class='pagination-last'>>></a> "
);
}
pageString.append(
"<select id='pageSelect' "
+onChange+
">"
+this.getOptions()+
"</select>"
);
}
}
else
if
(
"normalStyle"
.equalsIgnoreCase(this.pageStyle)) {
if
(this.getPageCount() ==1) {
pageString.append(
"<strong> 共1页</strong> "
);
}
else
{
if
(this.currentPage >1) {
pageString.append(
"<a class='pagination-first' "
+firstClick+
" title='首页' href='"
+ this.pageURL
+
"?currentPage=1'><<</a> "
);
pageString.append(
"<a class='pagination-prev' "
+preClick+
"title='上一页' href='"
+ this.pageURL
+
"?currentPage="
+ (this.currentPage -1)
+
"'><</a> "
);
}
else
{
pageString
.append(
"<a class='pagination-first'><<</a> "
);
pageString
.append(
"<a class='pagination-prev'><</a> "
);
}
pageString.append(
"<span class='pageinfo'>第"
+this.currentPage+
"页/"
+this.pageCount+
"页</span>"
);
if
(this.currentPage <this.getPageCount()) {
pageString.append(
"<a class='pagination-next' "
+nextClick+
" title='下一页' href='"
+ this.pageURL
+
"?currentPage="
+ (this.currentPage +1)
+
"'>></a> "
);
pageString.append(
"<a class='pagination-last' "
+lastClick+
"title='尾页' href='"
+ this.pageURL
+
"?currentPage="
+ (this.getPageCount()) +
"'>>></a> "
);
}
else
{
pageString
.append(
"<a class='pagination-next' >></a> "
);
pageString
.append(
"<a class='pagination-last'>>></a> "
);
}
pageString.append(
"<select id='pageSelect' "
+onChange+
">"
+this.getOptions()+
"</select>"
);
}
}
pageString.append(
"</span></div>"
);
this.pageDisplay = pageString.toString();
returnpageDisplay;
}
publicvoid setPageDisplay(String pageDisplay) {
this.pageDisplay = pageDisplay;
}
publicString getPageURL() {
returnpageURL;
}
publicvoid setPageURL(String pageURL) {
this.pageURL = pageURL;
}
publicint getPageCount() {
this.pageCount =this.rowCount %this.sizePerPage ==0 ? (this.rowCount /this.sizePerPage)
: (this.rowCount /this.sizePerPage) +1;
returnthis.pageCount;
}
publicvoid setPageCount(intpageCount) {
this.pageCount = pageCount;
}
publicint getRowCount() {
returnrowCount;
}
publicvoid setRowCount(introwCount) {
this.rowCount = rowCount;
}
publicint getCurrentPage() {
returncurrentPage;
}
publicvoid setCurrentPage(intcurrentPage) {
this.currentPage = currentPage;
}
publicint getSizePerPage() {
returnsizePerPage;
}
publicvoid setSizePerPage(intsizePerPage) {
this.sizePerPage = sizePerPage;
}
privateString getOptions(){
StringBuffer sb =
new
StringBuffer();
switch
(this.sizePerPage) {
case10:
sb.append(
"<option value=10>10</option><option value=20>20</option><option value=30>30</option><option value=50>50</option><option value=100>100</option>"
);
break
;
case20:
sb.append(
"<option value=20>20</option><option value=10>10</option><option value=30>30</option><option value=50>50</option><option value=100>100</option>"
);
break
;
case30:
sb.append(
"<option value=30>30</option><option value=10>10</option><option value=20>20</option><option value=50>50</option><option value=100>100</option>"
);
break
;
case50:
sb.append(
"<option value=50>50</option><option value=10>10</option><option value=20>20</option><option value=30>30</option><option value=100>100</option>"
);
break
;
case100:
sb.append(
"<option value=100>100</option><option value=10>10</option><option value=20>20</option><option value=30>30</option><option value=50>50</option>"
);
break
;
}
returnsb.toString();
}
}
PageBean page =
new
PageBean();
setPageInfo(list,request);
public
void setPageInfo(List list,HttpServletRequest request){
page.setCurrentPage(this.getCurrentPage());
if
(request.getParameter(
"perSize"
)==null){
page.setSizePerPage(20);
}
else
{
page.setSizePerPage(Integer.valueOf(request.getParameter(
"perSize"
)));
}
page.setRowCount(list.size());
page.setPageURL(request.getRequestURL().toString());
}
[css] view plaincopyprint?
.numberStyle,.normalStyle {
text-align:left;
}
.numberStyle a,.normalStyle a {
display: inline-block;
color: #5489F1;
text-decoration: none;
font-size: 14px;
font-weight:bold;
font-family: Geneva, Arial, Helvetica, sans-serif;
border: 1px solid #999;
width: 20px;
height: 20px;
line-height: 20px;
text-align: center;
background-position:center;
}
.numberStyle strong,.normalStyle strong {
display: inline-block;
color: #5489F1;
text-decoration: none;
font-size: 14px;
font-weight:bold;
font-family: Geneva, Arial, Helvetica, sans-serif;
border: 1px solid #999;
width: 20px;
height: 20px;
line-height: 20px;
text-align: center;
background-position:center;
}
.numberStyle a:hover,.normalStyle a:hover{
background-color: #d0d0d0;
}
.normalStyle .pageinfo{
font-size: 14px;
font-family: Geneva, Arial, Helvetica, sans-serif;
color: #5489F1;
}
[javascript] view plaincopyprint?
function
ajaxpage(action){
action=action+
"&perSize="
+$(
"#pageSelect"
).val();
$.ajax( {
type :
"POST"
,
url : action,
success :
function
(msg) {
}
});
}