MyBatis Pagehelper Paging Plug-ins use

Source: Internet
Author: User

People who have used MyBatis know that the mybatis itself is small and simple, SQL is written in XML, managed and optimized uniformly. Disadvantages Of course there are, for example, we use the process, to use the pagination, if in the most original way, 1. Query paging data, 2. Gets the paging length, which means that you need to use two methods to complete the paging. There is no better paging way, the Pagehelper paging plug-in is thus born, his principle is to use the MyBatis interceptor, in querying the database, intercept the SQL, and then modify to achieve pagination (if you just want to know the principle, MyBatis interceptor, You'll know what's going on after study.

This blog first shows you how to use, after a time to talk about his implementation principle.

1. Add maven dependencies

<dependency>
    <groupId>com.github.pagehelper</groupId>
    <artifactid>pagehelper </artifactId>
    <version>5.0.0</version>
</dependency>

2. Configure the Interceptor plug-in in the Spring configuration file (which can also be configured in MyBatis XML, which is not much said here)

<!--Configuration Sqlsessionfactory object--> <bean id= "Sqlsessionfactory" Org.mybatis.spring.SqlSessionFactoryBean "> <property name=" dataSource "ref=" DataSource "/> <PR Operty name= "configlocation" value= "Classpath:mybatis-config.xml"/> <property name= "TypeAliasesPackage" Val

        Ue= "com.aoChine.model.entity"/> <property name= "mapperlocations" value= "Classpath:mapper/*.xml"/>
                <!--Configure MyBatis paging pagehelper--> <property name= "Plugins" > <array>
                        <bean class= "Com.github.pagehelper.PageInterceptor" > <property name= "Properties" > <!--don't deserve anything, use the default configuration--> <value></value> &L  t;/property> </bean> </array> </property> </bean> 

3. Use

A) write the interface of the normal query statement

Interface:

b The interface is invoked at the service level to achieve paging.

Paging Plug-ins Use this is finished, the blog is only introduced the simplest way to use, if you need to know more content

This is the open source community above the plugin library address:
Https://github.com/pagehelper/Mybatis-PageHelper/blob/master/README_zh.md
If there is a problem: Add QQ Group: 211286137

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.