当前位置: 移动技术网 > IT编程>开发语言>Java > SqlHelper发布——比你期望的还要多的多(例如比MyBatis-Pagehelper性能更高)

SqlHelper发布——比你期望的还要多的多(例如比MyBatis-Pagehelper性能更高)

2019年06月04日  | 移动技术网IT编程  | 我要评论

陈茵薇个人资料,农夫最新导航,rebd-059

sqlhelper发布——比mybatis-pagehelper性能更高

起源

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

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

2) 扩展不方便

3) 配置复杂

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

5) 只支持mybatis

 

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

 

关键特性

  1. 支持mybatis, jfinal,ebean
  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

mybatis-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

国产数据库

x

√ (参见上述列表)

 

 

安装

可以在多种场景下使用,支持mybatis,jfinal,ebean等。先就说说mybatis下如何使用:

 

1)  与mybatis + springboot结合使用

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

    <dependency>
        <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>

 

 

支持

 

如对本文有疑问,请在下面进行留言讨论,广大热心网友会与你互动!! 点击进行留言回复

相关文章:

验证码:
移动技术网