1 PackageCom.java1234.util;2 3 Public classPageutil {4 //Pass in four parameters, Tagetutil is the head of the jump link, Totalnum is the total number, CurrentPage is the current page, pagesize is the number of each page can be displayed5 Public StaticString Genpagation (String TargetUrl,intTotalnum,intCurrentPage,intpageSize) {6 //define Totalpage, that is, the total number of pages is Totalpage,? When the remainder is 0, select the previous value, and select the second value when it is not set.7 intTotalpage=totalnum%pagesize==0?totalnum/pagesize:totalnum/pagesize+1;8 //Define a StringBuffer9StringBuffer pagecode=NewStringBuffer (); Ten //The TargetUrl that comes in is the front part of a jump link, paired up? Page=1 can jump to the homepage. OnePagecode.append ("<li><a href= '" +targeturl+ "? page=1 ' > Home </a></li>"); A //if it is the first page, you can no longer jump, class= ' disabled ' - if(currentpage==1){ -Pagecode.append ("<li class= ' disabled ' ><a href= ' # ' > Prev </a></li>"); the - } - //if it's not the first page, then the page of ' prev ' is currentPage-1 - Else{ +Pagecode.append ("<li><a href=" "+targeturl+"? page= "+ (currentPage-1) +" > Prev </a></li> "); - } + //This code is not very clear for the time being what it means A for(inti=currentpage-2;i<=currentpage+2;i++){ at // - if(i<1| | I>totalpage) { - Continue; - } - if(i=currentpage) { -Pagecode.append ("<li class= ' active ' ><a href= ' # ' >" +i+ "</a></li>"); in - } to Else{ +Pagecode.append ("<li><a href=" "+targeturl+"? page= "+i+" > "+i+" </a></li> "); - } the * } $ //If the current page is the last page, then the next page is gone, that is class= ' disabled 'Panax Notoginseng if(currentpage==totalpage) { -Pagecode.append ("<li class= ' disabled ' ><a href= ' # ' > Next </a></li>"); the + } A //if it is not the last page, then the next page is the current page currentpage+1 the Else{ +Pagecode.append ("<li><a href=" "+targeturl+"? Page "+ (currentpage+1) +" > Next </a></li> "); - } $ //Page=totalpage is a direct jump to the end of the $Pagecode.append ("<li><a href=" "+targeturl+"? page= "+totalpage+" ' > Last </a></li> "); - returnpagecode.tostring (); - } the -}
STRUTS2 Student Information Management System Chapter ③