分享

Mybatis 通用 Mapper首页、文档和下载

 雨后夜思 2015-11-07

12月12日北京OSC源创会 —— 开源技术的年终盛典 ?  

Mybatis通用Mapper

极其方便的使用Mybatis单表的增删改查

支持单表操作,不支持通用的多表联合查询

优点?

通用Mapper可以极大的方便开发人员。

为了让您更方便的了解通用Mapper,下面贴一段代码来看实际效果。

通用Mapper

通用Mapper可以缓存,全部针对单表操作,每个实体类都需要继承通用Mapper接口来获得通用方法。

示例代码:

CountryMapper mapper = sqlSession.getMapper(CountryMapper.class);
//查询全部
List<Country> countryList = mapper.select(new Country());
//总数
Assert.assertEquals(183, countryList.size());

//通用Example查询
Example example = new Example(Country.class);
example.createCriteria().andGreaterThan("id", 100);
countryList = mapper.selectByExample(example);
Assert.assertEquals(83, countryList.size());

//MyBatis-Generator生成的Example查询
CountryExample example2 = new CountryExample();
example2.createCriteria().andIdGreaterThan(100);
countryList = mapper.selectByExample(example2);
Assert.assertEquals(83, countryList.size());

CountryMapper代码如下:

public interface CountryMapper extends Mapper<Country> {
}

这里不说更具体的内容,如果您有兴趣,可以查看下面的项目文档

实体类注解

从上面效果来看也能感觉出这是一种类似hibernate的用法,因此也需要实体和表对应起来,因此使用了JPA注解。更详细的内容可以看下面的项目文档

Country代码:

public class Country {
    @Id
    private Integer id;
    @Column
    private String countryname;
    private String countrycode;
    //省略setter和getter方法
}

使用Mapper专用的MyBatis Generator插件 可以方便的生成这些(带注解的)实体类。

通用Mapper支持Mybatis-3.2.4及以上版本

更新日志

Maven坐标以及下载地址

如果你使用Maven,只需要添加如下依赖:

1
2
3
4
5
6
<dependency>
    <groupId>com.github.abel533</groupId>
    <artifactId>mapper</artifactId>
    <!-- 可以通过上面的更新日志来看最新的版本号 -->
    <version>x.x.x</version>
</dependency>

如果你想引入Jar包,你可以从下面的地址下载:

https://oss./content/repositories/releases/com/github/abel533/mapper/

http://repo1./maven2/com/github/abel533/mapper/

由于通用Mapper依赖JPA,所以还需要下载persistence-api-1.0.jar:

http://repo1./maven2/javax/persistence/persistence-api/1.0/

项目文档

通用Mapper

  1. 如何集成通用Mapper

  2. 如何使用通用Mapper

  3. 如何开发自己的通用Mapper

  4. 在Spring4中使用通用Mapper

  5. 如何使用Mapper专用的MyBatis Generator插件

作者信息

作者博客:http://blog.csdn.net/isea533

作者邮箱: abel533@gmail.com

Mybatis工具群: 211286137 (Mybatis相关工具插件等等)

推荐使用Mybatis分页插件:PageHelper分页插件

官方网站:www.

    本站是提供个人知识管理的网络存储空间,所有内容均由用户发布,不代表本站观点。请注意甄别内容中的联系方式、诱导购买等信息,谨防诈骗。如发现有害或侵权内容,请点击一键举报。
    转藏 分享 献花(0

    0条评论

    发表

    请遵守用户 评论公约

    类似文章 更多