Mybatis 通用 Mapper 3.3.3 发布

jopen 8年前

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());  
</div>

CountryMapper代码如下:

public interface CountryMapper extends Mapper<Country> {  }  
</div>

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

实体类注解

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

</h1>

3.3.3 - 2015-12-30

3.3.2 - 2015-12-12

  • 解决数据越界bug#73

  • 解决and少空格问题

  • 解决order by错误#74

  • tk.mybatis.spring.mapper.MapperScannerConfigurer中的属性mapperHelper增加setter和getter方法,方便通过代码进行配置

来自: http://www.oschina.net/news/69490/mybatis-mapper-3-3-3