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>