Use of Page Helper in MyBatis

Use of Page Helper in MyBatis

A brief introduction to PageHelper

PageHelper is an excellent open source mybatis paging plug-in in China. It supports basic mainstream and common databases, such as mysql,oracle and so on.
Its project address on github: pageHelper-MyBatis

Simple use of PageHelper

Step 1: Import dependencies in pom.xml


Step 2: Configure the interceptor plug-in in Spring's configuration file

 <!--To configure SqlSessionFactory factory-->
    <bean id="sqlSessionFactory" class="org.mybatis.spring.SqlSessionFactoryBean">
        <property name="dataSource" ref="dataSource"></property>
        <!--To configure pagehelper-->
        <property name="plugins">
                <bean class="com.github.pagehelper.PageInterceptor">
                    <property name="properties">
                            <prop key="helperDialect">oracle</prop>
                            <prop key="reasonable">true</prop>

Step 3: Use

Call PageHelper.startPage static method before you need to paginate MyBatis query method. The first MyBatis query method that follows this method will be paginated.

    public  List<Order> findAll(int page, int size) throws Exception {

        //The parameter pageNum is the page number value, and the parameter pageSize represents the number of bars displayed per page.
        List<Order> orderList=orderDao.findAll(page,size);
        return orderList;

Tags: Mybatis Spring github xml

Posted on Wed, 09 Oct 2019 19:09:45 -0700 by dvt85