SPRINGMVC Handwriting Paging Query

Source: Internet
Author: User

 PackageCom.neuedu.java7.baen; Public classPage {Private intCurrentPage = 1;//Current Page    Private intTotalPages;//Total Pages    Private intTotal//Record Total Rows    Private intPageSize = 5;//number of rows per page    Private intNextPage;//Next Page    Private intPrefpage;//Previous Page         PublicPage () {} PublicPage (intCurrentPage,intpageSize) {         This. currentpage =currentpage;  This. pageSize =pageSize; }         Public intGetcurrentpage () {returncurrentpage; }     Public voidSetcurrentpage (intcurrentpage) {         This. currentpage =currentpage; }     Public intgettotalpages () {totalpages= Total%pagesize = = 0?total/pagesize:total/pagesize+1; returnTotalPages; }     Public intgettotal () {returnTotal ; }     Public voidSettotal (intTotal ) {         This. Total =Total ; }     Public intgetpagesize () {returnpageSize; }     Public voidSetPageSize (intpageSize) {         This. pageSize =pageSize; }     Public intGetnextpage () {if(currentpage<totalpages) {NextPage= Currentpage+1; }Else{nextPage=currentpage; }        returnNextPage; }     Public intGetprefpage () {if(currentpage>1) {Prefpage= CurrentPage-1; }Else{prefpage=currentpage; }        returnPrefpage; }        }//Writing Method    /*** Paging Query * *@paramPagger *@return     */     PublicList<category>findlist (Page page); /*** Total Query Records * *@return     */     Public intfindtotal ();//Write Mapper Method<select id= "findtotal" resulttype= "int" >Select count (t.id) t from category T</select> <select id= "findlist" parametertype= "Com.neuedu.java7.baen.Page"Resultmap= "Categorymap" >Select*From (select RowNum rn, id,cname from category where RowNum&lt;= #{currentpage}*#{pagesize}) where RN &gt; (#{currentpage}-1) *#{pagesize}</select>//Write Action Control@RequestMapping ("/doall")     PublicString findalls (httpservletrequest request) {Page page=NewPage (); intCount =categoryservice.findtotal ();                 Page.settotal (count); Request.getsession (). SetAttribute ("Page", page); List<Category> Category =categoryservice.findlist (page); Request.getsession (). SetAttribute ("Category", category); return"List"; } @RequestMapping ("/page")     PublicString page (Integer pagesize,integer currentpage,httpservletrequest request) {Page page=NULL; if(Request.getsession (). getattribute ("page")! =NULL) {page= (page) request.getsession (). getattribute ("page"); }Else{page=NewPage (); }        if(pagesize!=NULL) {page.setpagesize (pageSize); }        if(currentpage!=NULL) {page.setcurrentpage (currentpage); } List<Category> Category =categoryservice.findlist (page); Request.setattribute ("Category", category); return"List"; }    //Write page encoding<tr> <td align= "left" colspan= "2" > per page <select name= "pageSize" id= "PageSize" style= "Background-color: # FFFF33 "onchange=" ToPage () "> <option value=" 5 "${page.pagesize==5?" Selected= ' selected ' ":" "}>5</option> <option value=" ${page.pagesize==10? " Selected= ' selected ' ":" "}>10</option> <option value=" "${page.pagesize==20?" Selected= ' selected ' ":" "}>20</option> </select> strips </td> <td align=" right "cols Pan= "3" ><a href= ". /category/page.do?currentpage=1 ">[home]</a> <a href=". /category/page.do?currentpage=${page.prefpage} "> Previous </a> <a href=". /category/page.do?currentpage=${page.nextpage} "> Next </a> <a href=". /category/page.do?currentpage=${page.totalpages} ">[last]</a></td> </td> </tr>

SPRINGMVC Handwriting Paging Query

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.