MyBatis Paging Implementation Process

Source: Internet
Author: User
First step: Encapsulating the paging bean
public class Paginationvo implements serializable{


Private static final long serialversionuid = 1L;


Private Integer page;//page that corresponds to Easyui pages

Private Integer rows;//rows corresponding to Easyui pages

Private Integer Begnum;

Private Integer Endnum;


Public Integer GetPage () {
return page;
}


public void Setpage (Integer page) {
this.page = page;
}


Public Integer getRows () {
return rows;
}


public void Setrows (Integer rows) {
This.rows = rows;
}


/**
* Returns the value of Begnum
* @return Begnum
*/

Public Integer Getbegnum () {
return begnum;
}



/**
* Set the value of Begnum
* @param begnum Begnum
*/
public void Setbegnum (Integer page, integer rows) {
This.begnum = (page-1) * rows;
}


/**
* Returns the value of Endnum
* @return Endnum
*/
Public Integer Getendnum () {
return endnum;
}


/**
* Set the value of Endnum
* @param endnum Endnum
*/
public void Setendnum (Integer endnum) {
This.endnum = Endnum;
}


/**
*
* Description Set Paging data
*/
public void Setpaginationdata () {
This.begnum = (page-1) * rows;
This.endnum = rows;
}
}








Step two: Business Vo inherits the above class
public class Forminfovo extends paginationvo{...}




Step Three: Call
JSON =new Gridlistjson ();
try {
Instance.setpaginationdata ();
Json.setrows (Userservice.finduserlist (instance));
Json.settotal (Userservice.getusertotal (instance));




Fourth step: Page.xml Paging Map File encapsulation
<?xml version= "1.0" encoding= "UTF-8"?>
<! DOCTYPE Mapper Public "-//mybatis.org//dtd mapper 3.0//en" "Http://mybatis.org/dtd/mybatis-3-mapper.dtd" >


<mapper namespace= "Page" >
<sql id= "Pagebegin" >
SELECT a.* from (
</sql>

<sql id= "Pageend" >
) A LIMIT #{begnum}, #{endnum}
</sql>

<sql id= "PageCount" >
SELECT count (1) as CNT
</sql>
</mapper>




Fifth step: Usermanamapper.xml Service Map File calling paging component
<select id= "finduserlist" parametertype= "Uservo"
resultmap= "Baseresultmap" >
<include refid= "Page.pagebegin"/> <!--paging component call prefix--
SELECT * FROM T_user
<include refid= "Page.pageend"/><!--paging component call suffix--
</select>





The configuration of the above two mapping files is added to the MyBatis
<mappers>
<mapper resource= "Mybatis/page.xml" ></mapper>
<mapper resource= "Mybatis/usermanamapper.xml"/>
</mappers>






Front Desk Description:


<table id= "tt" class= "Easyui-datagrid" style= "width:600px;height:250px"
Url= "datagrid2_getdata.php"
title= "Load Data" iconcls= "Icon-save"
Rownumbers= "true" pagination= "true" >
<thead>
<tr>
<th field= "userid" width= ">user id</th>"
<th field= "name" width= ">user name</th>"
</tr>
</thead>
</table>
We define the DataGrid's DataGrid and set the ' pagination ' property to True, which will generate a paging toolbar at the bottom of the DataGrid pagination will send 2 parameters to the server:
Page: page number, starting at value 1.
Rows: Display lines per page

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.