Solon v3.4.0

::mybatis-pagehelper

</> markdown
<dependency>
    <groupId>com.github.pagehelper</groupId>
    <artifactId>pagehelper</artifactId>
    <version>6.1.1</version>
    <exclusions>
        <exclusion>
            <groupId>org.mybatis</groupId>
            <artifactId>mybatis</artifactId>
        </exclusion>
    </exclusions>
</dependency>

1、描述

数据扩展插件,可为 mybatis-solon-plguin 插件提供分页支持。mybatis-plus 有自带的分页插件,使用的必要性不大。

  • 代码仓库:

https://github.com/pagehelper/Mybatis-PageHelper

  • 使用说明

HowToUse.md

  • 可配置项目参考

PageHelperStandardProperties

2、配置示例

#数据源配置块(名字按业务需要取,与 @Db 那边对起来就好)
solon.dataSources:
  db1!:
    class: "com.zaxxer.hikari.HikariDataSource"
    jdbcUrl: jdbc:mysql://localhost:3306/rock?useUnicode=true&characterEncoding=utf8&autoReconnect=true&rewriteBatchedStatements=true
    driverClassName: com.mysql.cj.jdbc.Driver
    username: root
    password: 123456

#映射配置
mybatis.db1:
    typeAliases:    #支持包名 或 类名(.class 结尾)
        - "demo.model"
    mappers:        #支持包名 或 类名(.class 结尾)或 xml(.xml结尾)
        - "demo.dso.mapper"
    plugins:
        - class: com.github.pagehelper.PageInterceptor #分页组件的配置(配置荐参考 PageHelperStandardProperties;配置前缀名随意,注入时使用此名即可)
          offsetAsPageNum: true
          rowBoundsWithCount: true
          pageSizeZero: true
          reasonable: false
          params: pageNum=pageHelperStart;pageSize=pageHelperRows;
          supportMethodsArguments: false

3、应用示例

//应用
@Component
public class AppService{
    @Db
    AppMapper appMapper; 
    
    public List<AppxModel> test(){
        //分页查询
        PageHelper.offsetPage(2, 2);
        return appxMapper.appx_get_page();
    }
    
    public Page<AppxModel> test2(){
        //分页查询(带总数)
        return PageHelper.startPage(2, 2).doSelectPage(()-> appxMapper.appx_get_page());
    }
}