Mybatis 文档篇 3.0:Mapper XML

Mapper XML 简要说明

The true power of MyBatis is in the Mapped Statements. This is where the magic happens.
作用:MyBatis 真正强大的地方在于语句映射。这才是它的魔力所在。

For all of their power, the Mapper XML files are relatively simple. Certainly if you were to compare them to the equivalent JDBC code, you would immediately see a savings of 95% of the code.MyBatis was built to focus on the SQL, and does its best to stay out of your way.
优势:相对于它强大的特性,Mapper XML 文件就相对简单多了。如果拿它跟相同功能的 JDBC 代码相比,你会立即发现它省去了几乎95%的代码。MyBatis 就是针对 SQL 构建的,并且比其他方法做的更好。

The Mapper XML files have only a few first class elements (in the order that they should be defined):
内容:Mapper XML 文件只有几个一级元素(按照它们应该被定义的顺序):

  • cache – Configuration of the cache for a given namespace.
    cache:为给定的命名空间配置缓存。

  • cache-ref – Reference to a cache configuration from another namespace.
    cache-ref:其他命名空间缓存配置的引用。

  • resultMap – The most complicated and powerful element that describes how to load your objects from the database result sets.
    resultMap:最复杂也是最强大的元素,描述了如何从数据库结果集加载对象。

  • parameterMap – Deprecated! Old-school way to map parameters. Inline parameters are preferred and this element may be removed in the future. Not documented here.
    parameterMap:已废弃!老式风格参数映射。行内参数是首选,所以这个元素在将来可能会被移除掉。

  • sql – A reusable chunk of SQL that can be referenced by other statements.
    sql:可以被其他语句引用的可重用 SQL 语句块。

  • insert – A mapped INSERT statement.
    insert:映射 insert 语句。

  • update – A mapped UPDATE statement.
    update:映射 update 语句。

  • delete – A mapped DELETE statement.
    delete:映射 delete 语句。

  • select – A mapped SELECT statement.
    select:映射 select 语句。

Mapper XML 详细请查看

  • select
  • insert, update and delete
  • sql
  • Parameters
  • Result Maps
  • Auto-mapping
  • cache

最后

说明:MyBatis 官网提供了简体中文的翻译,但个人觉得较为生硬,甚至有些地方逻辑不通,于是自己一个个重新敲着翻译的(都不知道哪里来的自信...),有些地方同官网翻译有出入,有些倔强地保留了自己的,有的实在别扭则保留了官网的,这些都会在实践中一一更正。鉴于个人英文能力有限,文章中保留了官方文档原英文介绍(个别地方加以调整修剪),希望有缘看到这里的朋友们能够有自己的理解,不会被我可能错误或不合理的翻译带跑偏(〃'▽'〃),欢迎指正!

当前版本:mybatis-3.5.0
官网文档:MyBatis
官网翻译:MyBatis 简体中文
项目实践:MyBatis Learn

你可能感兴趣的:(Mybatis 文档篇 3.0:Mapper XML)