PageHelper Spring Boot Starter

repository·master·Indexed 23 days ago

https://github.com/pagehelper-org/pagehelper-spring-boot

A Spring Boot starter for integrating the PageHelper MyBatis pagination plugin. It automates the configuration and lifecycle management of the pagination interceptor, supporting PageHelper 6.x. Features include asynchronous count support, custom dialect aliases, and control over interceptor execution order via PageHelperAutoConfiguration.

Tokens
678
Snippets
5
Records
5
Agent score
32%

What's inside pagehelper-spring-boot-starter

  1. Install PageHelper Spring Boot Starter

    master

    To integrate PageHelper pagination into your Spring Boot project, add the pagehelper-spring-boot-starter dependency to your pom.xml. This starter supports PageHelper 6.x.

    <dependency>
      <groupId>com.github.pagehelper</groupId>
      <artifactId>pagehelper-spring-boot-starter</artifactId>
      <version>4.1.1</version>
    </dependency>
  2. Configure PageHelper properties

    master

    Normally, no configuration is required. If you need to customize PageHelper, use the pagehelper prefix in your application.properties or application.yml.

    Most common parameters support IDE auto-completion and kebab-case style (e.g., offset-as-page-num). If you are using custom extended parameters that do not support auto-completion, use the original camelCase parameter names. For a full list of available properties, refer to the official PageHelper documentation.

    pagehelper.propertyName=propertyValue
  3. Enable asynchronous count in PageHelper

    master

    Starting from version 2.0.0, PageHelper supports asynchronous count. You can enable this globally via configuration:

    pagehelper.async-count=true

    Alternatively, you can enable it for a single specific request using the PageHelper API:

    PageHelper.startPage(1, 10).enableAsyncCount();
  4. Control Interceptor Order

    master

    If you need to control the execution order of interceptor plugins relative to PageHelper, use the @AutoConfigureAfter or @AutoConfigureBefore annotations on your configuration class, referencing PageHelperAutoConfiguration.class.

    @AutoConfigureAfter(PageHelperAutoConfiguration.class)
    //Or
    @AutoConfigureBefore(PageHelperAutoConfiguration.class)
  5. Configure dialect aliases and default count

    master

    In version 1.2.4, two specific configuration options were added:

    1. dialect-alias: Allows configuring custom implementations for specific databases via aliases. Multiple configurations are separated by a semicolon (;).
    2. default-count: Controls whether a count query is executed for methods that do not explicitly include a count query. Defaults to true.

    Example configuration:

    pagehelper.dialect-alias=oracle=com.github.pagehelper.dialect.helper.OracleDialect
    pagehelper.default-count=false