MyBatis-Pager: 一个轻量且优雅的 MyBatis 分页组件

Maven Apache 2
jdk-8 jdk-11 jdk-17

优点

  • 无侵入:仅需在mapper层接口中增加Pager<T>参数即可。
  • 零配置:无需额外增加配置项,能够自动推断数据库分页方言。

使用方法

SpringBoot2 项目引入maven依赖

<dependency>
    <groupId>cn.codest</groupId>
    <artifactId>mybatis-pager-spring-boot2-starter</artifactId>
    <version>1.0</version>
</dependency>

SpringBoot3 项目引入maven依赖

<dependency>
    <groupId>cn.codest</groupId>
    <artifactId>mybatis-pager-spring-boot3-starter</artifactId>
    <version>1.0</version>
</dependency>

Mapper XML中定义查询SQL语句

<select id="selectPage" resultType="cn.codest.mybatispagerspringboot2test.model.User">
    select
        id,
        name,
        mobile
    from t_user
    <if test="null != name and '' != name">
        where name like concat(#{name}, '%')
    </if>
</select>

定义Mapper接口,参数中需要包含Pager分页查询对象

public interface UserMapper {

    List<User> selectPage(@Param("name") String name, Pager<User> pager);

}

调用Mapper接口,查询分页数据

Pager<User> pager = Pager.of(1);
userMapper.selectPage(null, pager);
log.info("result = [{}]", pager);

带条件查询

Pager<User> pager = Pager.of(1);
userMapper.selectPage("郭", pager);
log.info("result = [{}]", pager);

支持的数据库

目前jDialects自带支持以下83种数据库方言

  • AccessDialect
  • Cache71Dialect
  • CobolDialect
  • CUBRIDDialect
  • DamengDialect
  • DataDirectOracle9Dialect
  • DB2390Dialect
  • DB2390V8Dialect
  • DB2400Dialect
  • DB297Dialect
  • DB2Dialect
  • DbfDialect
  • DerbyDialect
  • DerbyTenFiveDialect
  • DerbyTenSevenDialect
  • DerbyTenSixDialect
  • ExcelDialect
  • FirebirdDialect
  • FrontBaseDialect
  • GBaseDialect
  • H2Dialect
  • HANAColumnStoreDialect
  • HANARowStoreDialect
  • HSQLDialect
  • Informix10Dialect
  • InformixDialect
  • Ingres10Dialect
  • Ingres9Dialect
  • IngresDialect
  • InterbaseDialect
  • JDataStoreDialect
  • MariaDB102Dialect
  • MariaDB103Dialect
  • MariaDB10Dialect
  • MariaDB53Dialect
  • MariaDBDialect
  • MckoiDialect
  • MimerSQLDialect
  • MySQL55Dialect
  • MySQL57Dialect
  • MySQL57InnoDBDialect
  • MySQL5Dialect
  • MySQL5InnoDBDialect
  • MySQL8Dialect
  • MySQLDialect
  • MySQLInnoDBDialect
  • MySQLMyISAMDialect
  • Oracle10gDialect
  • Oracle12cDialect
  • Oracle8iDialect
  • Oracle9Dialect
  • Oracle9iDialect
  • OracleDialect
  • ParadoxDialect
  • PointbaseDialect
  • PostgresPlusDialect
  • PostgreSQL81Dialect
  • PostgreSQL82Dialect
  • PostgreSQL91Dialect
  • PostgreSQL92Dialect
  • PostgreSQL93Dialect
  • PostgreSQL94Dialect
  • PostgreSQL95Dialect
  • PostgreSQL9Dialect
  • PostgreSQLDialect
  • ProgressDialect
  • RDMSOS2200Dialect
  • SAPDBDialect
  • SQLiteDialect
  • SQLServer2005Dialect
  • SQLServer2008Dialect
  • SQLServer2012Dialect
  • SQLServerDialect
  • Sybase11Dialect
  • SybaseAnywhereDialect
  • SybaseASE157Dialect
  • SybaseASE15Dialect
  • SybaseDialect
  • Teradata14Dialect
  • TeradataDialect
  • TextDialect
  • TimesTenDialect
  • XMLDialect
posted @ 2024-08-06 10:37  codest  阅读(4)  评论(0编辑  收藏  举报