Mybatis介绍及原理简介

Mybatis介绍及原理简介

1. Mybatis介绍

MyBatis is a first class persistence framework with support for custom SQL, stored procedures
and advanced mappings. MyBatis eliminates almost all of the JDBC code and manual setting of
parameters and retrieval of results. MyBatis can use simple XML or Annotations for configuration
and map primitives, Map interfaces and Java POJOs (Plain Old Java Objects) to database records.

译:
Mybatis是一个一流的持久框架,支持自定义SQL,存储过程和高级Mappings。 Mybatis减少了很多JDBC代码和手工设置的参数和提取结果步骤。
Mybatis可以使用一个简单的XML配置文件或者Annotation来配置和匹配实体,把接口和对应数据库记录的JAVA POJOs匹配起来。

Wiki:

Unlike ORM frameworks, MyBatis does not map Java objects to database tables but Java methods to SQL statements.

MyBatis lets you use all your database functionality like stored procedures, views, queries of any complexity and vendor proprietary features. It is often a good choice for legacy or de-normalized databases or to obtain full control of SQL execution.

It simplifies coding compared to JDBC. SQL statements are executed with a single line.

MyBatis provides a mapping engine that maps SQL results to object trees in a declarative way.

SQL statements can be built dynamically by using a built-in language with XML-like syntax or with Apache Velocity using the Velocity integration plugin.

MyBatis integrates with Spring Framework and Google Guice. This feature allows one to build business code free of dependencies.

MyBatis supports declarative data caching. A statement can be marked as cacheable so any data retrieved from the database will be stored in a cache and future executions of that statement will retrieve the cached data instead hitting the database. MyBatis provides a default cache implementation based on a Java HashMap and default connectors for integrating with: OSCache, Ehcache, Hazelcast and Memcached. It provides an API to plug other cache implementations.

译:
不像其他持久框架一样,Mybatis并不把JAVA POJO和数据库表对应起来而是把JAVA代码中的办法与SQL语句匹配起来。

Mybatis让你使用数据库所用的功能,比如存储过程、视图、包含不同数据库复杂的查询语句。它经常是一个比较好的选择对于遗留或者非规范的数据库,并且拥有应用于全部的SQL执行能力。

相比JDBC而言,它简化了变成。SQL语句可以只使用一行来执行。

Mybatis提供一个Mapping的引擎,这个引擎可以以一种声明的方式将SQL语句结果匹配JAVA对象上。

SQL语句可以动态的创建,者需要使用类似XML语法的内建语言或者apache 整合插件(没翻译明白).

Mybatis可以与Spring框架和Google Guice一起使用。这可以使你不用考虑依赖的问题创建出业务代码。

Mybatis支持声明的data缓存。一个语句可以打上标记为需要缓存,这样这个语句的结果就会记录到缓存中,这样将来的执行就不用再去数据库中查询。Mybatis支持一个默认的基于JAVA HashMap和默认整合系统缓存,Ehcache,Hazelcast和Memcached的缓存实现。它提供一个API,可以把其他缓存实现的方法以插件形式插入进来。

MyBatis is a fork from iBATIS, and according to Wikipedia most of iBATIS’ developers moved over to MyBatis too. The iBATIS project is currently marked as Inactive, therefore you should go with MyBatis for new projects and only use iBATIS if you’re maintaining an existing project which already uses iBATIS.(引入依据Mybatis的区别)

2.原理理解

主要完成两件事:
1. 根据JDBC规范建立数据库的连接
2. 通过反射打通对象和数据库之间的关系

其实它是一种典型的交互性框架,先准备好必须的交互条件,然后构建一个交互的环境。交互环境还划分为会话,每次的会话都有一个环境。当这些都准备好后,剩下的就是交互数据。其实涉及到网络通信,一般都是类似的处理方式。

主要的类介绍:
SqlMapClient接口定义了客户端的操作行为,包括select,insert,update和delete.
SqlMapSession主要定义了语句执行环境。
SqlMapClientImpl继承SqlMapClient和SqlMapSession的实现类,然后就可以操作了。

  • 1
    点赞
  • 3
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值