When spring boot integrates mybatis, paging is required, we first add maven support
<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 in application.yml (yml that spring needs to read)
pagehelper:
helperDialect: mysql
reasonable: true
supportMethodsArguments: true
params: count=countSql
Then restart.
The configuration file will eventually be read by java and finally injected into the spring bean, so our second method is to configure its bean class. Hot loading is convenient for modification. Of course, the first method is simpler.
Method 2: Create a new PageHeleperConfig under the annotation coverage 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]
*/
@Configuration
public 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 basics of pageHelper are:
import com.github.pagehelper.Page; import com.github.pagehelper.PageHelper;
Page<T> tPage= PageHelper.startPage(page,limit);
The query statement of the next sentence is used for paging. You just need to receive with List<T>
If you have questions, you can download the open source project lenos rapid development scaffolding and spring boot version to familiarize yourself with learning.
Address: https://gitee.com/bweird/lenosp