SqlHelper发布—比PageHelper性能更高git
前段时间开启了一个新的项目,在选择分页插件时,发现github上很流行的一个是pagehelper,在百度上搜索了一下,使用量。因为项目紧急,所先拿来用了。可是我知道它并不适合咱们。缘由是它有以下几个缺点:github
1) 对国产数据库支持不足spring
2) 扩展不方便sql
3) 配置复杂数据库
4) 性能底下 (不要喷我, 由于它不是用的占位符?,发挥不了PrepareSatement的优点)springboot
5) 只支持MyBatismybatis
鉴于它的这些不足,我就趁闲暇时间新开发了一款解决上述缺点的分页工具,它已经在公司里的两个项目获得了验证。但它不单单是个分页工具那么简单,目前支持的特性有Pagination、UrlParser,将来会支持更多特性。oracle
若是你想知道全部的数据库排名的话,你能够在这里找到: DB Engines.app
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下如何使用:ide
此应用环境下,只需导入下列包便可:
<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>
此应用环境下,使用也不麻烦。
第一步,导入依赖:
<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.jar移除,导入下面的包便可。
<dependency> <groupId>com.github.fangjinuo.sqlhelper</groupId> <artifactId>sqlhelper-mybatis-over-pagehelper</artifactId> <version>${sqlhelper.version}</version> </dependency>