Mybatis-plus 使用PageHelper分頁插件

① pom文件導入PageHelper依賴

<!-- pageHelper 依賴 -->
<dependency>
	<groupId>com.github.pagehelper</groupId>
	<artifactId>pagehelper</artifactId>
	<version>${pagehelper.version}</version>
</dependency>
<dependency>
	<groupId>com.github.jsqlparser</groupId>
	<artifactId>jsqlparser</artifactId>
	<version>${jsqlparser.version}</version>
</dependency>

 

② application.properties中添加PageHelper配置

## PageHelper分頁插件
# 分頁插件使用哪種方言
pagehelper.helperDialect=mysql
# 分頁合理化參數:當該參數設置爲 true 時,pageNum<=0 時會查詢第一頁, pageNum>pages(超過總數時),會查詢最後一頁。默認false 時,直接根據參數進行查詢。
pagehelper.reasonable=true
pagehelper.supportMethodsArguments=true
pagehelper.params=count=countSql

 

③ 添加Mybatis-plus分頁插件配置,並設置分頁插件爲PageHelper

/**
 * 創建分頁插件
 *
 */
@Configuration
public class MybatisPlusConfig {

    @Bean
    public PaginationInterceptor paginationInterceptor() {
        return new PaginationInterceptor();
    }

    @Bean
    ConfigurationCustomizer mybatisConfigurationCustomizer() {
        return configuration -> configuration.addInterceptor(new com.github.pagehelper.PageInterceptor());
    }
}

 

發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章