SqlHelper发布—比PageHelper性能更高

起源

前段时间开启了一个新的项目,在选择分页插件时,发现github上很流行的一个是pagehelper,在百度上搜索了一下,使用量。由于项目紧急,所先拿来用了。但是我知道它并不适合我们。原因是它有如下几个缺点:

1) 对国产数据库支持不足

2) 扩展不方便

3) 配置复杂

4) 性能底下 (不要喷我, 因为它不是用的占位符?,发挥不了PrepareSatement的优势)

5) 只支持MyBatis

鉴于它的这些不足,我就趁闲暇时间新开发了一款解决上述缺点的分页工具,它已经在公司里的两个项目得到了验证。但它不仅仅是个分页工具那么简单,目前支持的特性有Pagination、UrlParser,未来会支持更多特性。

关键特性

  1. 支持MyBatis, JFinal,Ebean,Mango
  2. 支持 90+ 种数据库, 支持列表参见 here. 包含了几乎所有的国产数据库:
  • TiDB (北京平凯星辰科技))
  • Doris (Apache Doris,百度研发)
  • MaxCompute (阿里巴巴)
  • K-DB (浪潮)
  • GBase (南大通用)
  • DM (达梦)
  • OSCAR (神州通用)
  • HighGo (瀚高)
  • KingBase (金仓)
  • OpenBase (东软)
  • SequoiaDB (巨杉)

如果你想知道所有的数据库排名的话,你可以在这里找到: DB Engines.

  1. 同一个应用中支持多种数据库
  2. 不需要配置dialect,可以自动的获取。
  3. 比 Mybatis-PageHelper性能更高, 原因是limit , offset等参数使用 PrepareStatement placeholder '?' , Mybatis是硬编码拼接的
  4. 通过Java SPI的方式支持了插件
  5. 支持 spring boot 1.x , 2.x
  6. 支持 mybatis 3.x
  7. 支持 JDK6+

Vs Pagehelper

metric pagehelper sqlhelper
databases 13 90+
multiple databases in runtime
auto detect dialect
plugin
PrepareStatement with '?' X
mybatis 3.x 3.x
spring boot 1.x, 2.x 1.x, 2.x
JDK 1.6+ 1.6+
jFinal X
EBean X
Mango X
国产数据库 X √ (参见上述列表)

安装

可以在多种场景下使用,支持MyBatis,JFinal,EBean等。先就说说MyBatis下如何使用:

1)  与Mybatis + SpringBoot结合使用

此应用环境下,只需导入下列包即可:

        <groupId>com.github.fangjinuo.sqlhelper</groupId>
<artifactId>sqlhelper-mybatis-spring-boot-autoconfigure</artifactId>
<version>${sqlhelper.version}</version>
</dependency>
<dependency>
<groupId>com.github.fangjinuo.sqlhelper</groupId>
<artifactId>sqlhelper-mybatis-spring-boot-starter</artifactId>
<version>${sqlhelper.version}</version>
</dependency>

2)与MyBatis (无spring boot)结合使用

此应用环境下,使用也不麻烦。

第一步,导入依赖:

<dependency>
<groupId>com.github.fangjinuo.sqlhelper</groupId>
<artifactId>sqlhelper-dialect</artifactId>
<version>${sqlhelper.version}</version>
</dependency>

第二步:配置插件:

<configuration>
...
<databaseIdProvider type="DB_VENDOR">
<property name="SQL Server" value="sqlserver"/>
<property name="DB2" value="db2"/>
<property name="Oracle" value="oracle" />
</databaseIdProvider>
...
<settings>
...
<setting name="defaultScriptingLanguage" value="com.github.fangjinuo.sqlhelper.mybatis.plugins.pagination.CustomScriptLanguageDriver" />
...
</settings>
...
</configuration> <plugins>
<plugin interceptor="com.github.fangjinuo.sqlhelper.mybatis.plugins.pagination.MybatisPaginationPlugin" />
</plugins>

使用

 @GetMapping
public PagingResult list(){
User queryCondtion = new User();
queryCondtion.setAge(10);
PagingRequest request = new PagingRequest()
.setPageNo(1)
.setPageSize(10);
PagingRequestContextHolder.getContext().setPagingRequest(request);
List users = userDao.selectByLimit(queryCondtion);
request.getResult().setItems(users);
return request.getResult();
}

从mybatis-pagehelper迁移

为了兼容已有的应用,特意提供了从mybatis-pagehelper迁移工具。使用也很简单,把mybatis-pagehelper.jar移除,导入下面的包即可。

 <dependency>
<groupId>com.github.fangjinuo.sqlhelper</groupId>
<artifactId>sqlhelper-mybatis-over-pagehelper</artifactId>
<version>${sqlhelper.version}</version>
</dependency>

支持

https://github.com/fangjinuo/sqlhelper

最新文章

  1. [CareerCup] 17.6 Sort Array 排列数组
  2. PHP 页面自动刷新可借助JS来实现,简单示例如下:
  3. Android Ant批量打包
  4. BestCoder Round #50 (div.1) 1001 Distribution money (HDU OJ 5364)
  5. VC 绘图技巧--自定义形状图形
  6. 修改servu数据库密码 servu加密方式
  7. logrotate日志轮转配置文档
  8. github pages绑定域名
  9. java关于redis的快速配置
  10. Django实现支付宝支付
  11. &lt;转&gt;jmeter(十一)JDBC Request之Query Type
  12. angularjs探秘&lt;五&gt; 举足轻重的scope
  13. python get请求
  14. MYSQL之You can&#39;t specify target table for update in FROM clause解决办法
  15. Kubernetes探索学习002--Kubernetes的基本使用
  16. VMW虚拟机生成的文件说明
  17. 微软TechNet关于TLS的细节的描述
  18. artdialog自定义多个按钮
  19. Vim求生
  20. MySQL八:视图、触发器、事物、存储过程、函数

热门文章

  1. Python 用hashlib求中文字符串的MD5值 (转自 haungrui的专栏)
  2. [官网]Postgresql 的客户端应用 pg_config
  3. Counting Cliques(HDU-5952)【DFS】
  4. scratch少儿编程第一季——04、想要做到有的放矢,瞄准方向很重要
  5. 01背包变种 第k解问题 hdu 2639
  6. (一)Struts2 基础
  7. 在sublime3中运行python文件
  8. sql语句分页多种方式
  9. mybatis查询foreach使用
  10. Linux--CentOS 安装 Docker 教程