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