Mybatis 通用 Mapper 3.3.3 發布

jopen 10年前發布 | 21K 次閱讀

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

CountryMapper代碼如下:

public interface CountryMapper extends Mapper<Country> {
}
</div> </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

 本文由用戶 jopen 自行上傳分享,僅供網友學習交流。所有權歸原作者,若您的權利被侵害,請聯系管理員。
 轉載本站原創文章,請注明出處,并保留原始鏈接、圖片水印。
 本站是一個以用戶分享為主的開源技術平臺,歡迎各類分享!