See pagehelper-spring-boot, which is very convenient to use. For more PageHelper, you can click https://github.com/pagehelper/Mybatis-PageHelper.
When spring boot integrates mybatis, we need to paginate it first.
<dependency> <groupId>com.github.pagehelper</groupId> <artifactId>pagehelper</artifactId> <version>5.1.2</version> </dependency> <dependency> <groupId>com.github.pagehelper</groupId> <artifactId>pagehelper-spring-boot-autoconfigure</artifactId> <version>1.2.3</version> </dependency> <dependency> <groupId>com.github.pagehelper</groupId> <artifactId>pagehelper-spring-boot-starter</artifactId> <version>1.2.3</version> </dependency>
Method 1: We add it in application.yml(yml that needs to be read in spring)
pagehelper: helperDialect: mysql reasonable: true supportMethodsArguments: true params: count=countSql
Then restart.
The configuration file will eventually be read by Java and will be injected into the spring bean. Therefore, our second method is to configure its bean class. Hot loading is easy to modify. Of course, the method is simpler.
Method 2: Create a new PageHeleperConfig under the annotation cover package
import com.github.pagehelper.PageHelper;import java.util.Properties;import org.springframework.context.annotation.Bean;import org.springframework.context.annotation.Configuration;/** * @author zhuxiaomeng * @date 2018/1/2. * @email [email protected] */@Configurationpublic class PageHelperConfig { @Bean public PageHelper getPageHelper(){ PageHelper pageHelper=new PageHelper(); Properties properties=new Properties(); properties.setProperty("helperDialect","mysql"); properties.setProperty("reasonable","true"); properties.setProperty("supportMethodsArguments","true"); properties.setProperty("params","count=countSql"); pageHelper.setProperties(properties); return pageHelper; }}
The basic knowledge of pageHelper is:
import com.github.pagehelper.Page;import com.github.pagehelper.PageHelper;
Page<T> tPage= PageHelper.startPage(page,limit);
The next query statement is used to paginate. You just need to receive it with List<T>
If you have questions, you can download the open source project Lenos to quickly develop scaffolding, and the spring boot version is familiar with learning.
Address: https://gitee.com/bweird/lenosp
The above is all the content of this article. I hope it will be helpful to everyone's learning and I hope everyone will support Wulin.com more.