发布于 2017-08-01 01:57:18 | 336 次阅读 | 评论: 0 | 来源: 网友投递

这里有新鲜出炉的MyBatis教程,程序狗速度看过来!

MyBatis 基于Java的持久层框架

MyBatis 本是apache的一个开源项目iBatis, 2010年这个项目由apache software foundation 迁移到了google code,并且改名为MyBatis 。


Mybatis分页插件 - PageHelper 5.0.4 发布了。   如果你也在用Mybatis,建议尝试该分页插件,这一定是最方便使用的分页插件。

该插件目前支持以下数据库的物理分页

  1. Oracle

  2.  Mysql

  3. MariaDB

  4. SQLite

  5. Hsqldb

  6. PostgreSQL

  7. DB2

  8. SqlServer(2005+)

  9. Informix

  10. H2

  11. SqlServer2012

  12. Derby

  13. Phoenix

如果你使用 Maven 可以在pom.xml 中添加下面的依赖:

<dependency>      <groupId>com.github.pagehelper</groupId>      <artifactId>pagehelper</artifactId>      <version>5.0.4</version>  </dependency>

如果使用Spring Boot,可以直接添加下面的依赖:

<dependency>      <groupId>com.github.pagehelper</groupId>      <artifactId>pagehelper-spring-boot-starter</artifactId>      <version>1.1.3</version>  </dependency>

     5.0.4 

  • 增加对Phoenix数据库的简单配置支持,配置helperDialect=phoenix即可,也可以自动识别Phoenix数据库的 jdbc url。

  • count 查询的缓存msCountMapkey 改为String类型,key 为 count 查询的MappedStatement的 id。

  • 增加countSuffixcount 查询后缀配置参数,该参数是针对PageInterceptor配置的,默认值为_COUNT。

  • 增加手写 count 查询支持,详情看下面介绍。

    增加手写 count 查询支持

    增加countSuffixcount 查询后缀配置参数,该参数是针对PageInterceptor配置的,默认值为_COUNT。

    分页插件会优先通过当前查询的 msId +countSuffix查找手写的分页查询。

    如果存在就使用手写的 count 查询,如果不存在,仍然使用之前的方式自动创建 count 查询。

    例如,如果存在下面两个查询:

<select id="selectLeftjoin" resultType="com.github.pagehelper.model.Country">      select a.id,b.countryname,a.countrycode from country a      left join country b on a.id = b.id      order by a.id  </select>  <select id="selectLeftjoin_COUNT" resultType="Long">      select count(distinct a.id) from country a      left join country b on a.id = b.id  </select>

上面的countSuffix使用的默认值_COUNT,分页插件会自动获取到selectLeftjoin_COUNT查询,这个查询需要自己保证结果数正确。

返回值的类型必须是resultType="Long",入参使用的和selectLeftjoin查询相同的参数,所以在 SQL 中要按照selectLeftjoin的入参来使用。

因为selectLeftjoin_COUNT方法是自动调用的,所以不需要在接口提供相应的方法,如果需要单独调用,也可以提供。

上面方法执行输出的部分日志如下:

DEBUG [main] - ==>  Preparing: select count(distinct a.id) from country a left join country b on a.id = b.id   DEBUG [main] - ==> Parameters:   TRACE [main] - <==    Columns: C1  TRACE [main] - <==        Row: 183  DEBUG [main] - <==      Total: 1  DEBUG [main] - Cache Hit Ratio [com.github.pagehelper.mapper.CountryMapper]: 0.0  DEBUG [main] - ==>  Preparing: select a.id,b.countryname,a.countrycode from country a left join country b on a.id = b.id order by a.id LIMIT 10   DEBUG [main] - ==> Parameters:   TRACE [main] - <==    Columns: ID, COUNTRYNAME, COUNTRYCODE  TRACE [main] - <==        Row: 1, Angola, AO  TRACE [main] - <==        Row: 2, Afghanistan, AF  TRACE [main] - <==        Row: 3, Albania, AL


历史版本 :
Mybatis 通用 Mapper 3.4.5 发布,增加代码生成器插件
MyBatis 逆向工程 MyBatis-CMEU v2.1.2 发布
Mybatis 分页插件 PageHelper 5.1.2 发布
mybatis-plus 2.1.1 发布,新增 mybatis 多租户 SQL 解析
MyBatis-Guice 3.10 发布,修复多项错误
mybatis-plus 2.1.1-SNAPSHOT,代号:小锅盖
MyBatis Ignite 1.0.6 发布,MyBatis 缓存插件
MyBatis 3.4.5 发布,Java 数据持久层框架
mybatis-plus 2.1.0 发布,代号:小秋秋
MyBatis 逆向工程 MyBatis-CMEU v2.1.0 发布
Mybatis 分页插件 PageHelper 5.0.4 发布
Mybatis-Plus 2.0.9 发布,简化开发 mybatis 快速入门
最新网友评论  共有(0)条评论 发布评论 返回顶部

Copyright © 2007-2017 PHPERZ.COM All Rights Reserved   冀ICP备14009818号  版权声明  广告服务