当前位置: 代码迷 >> XML/SOAP >> 跟小弟我一起学Mybatis之(四)-Mapper XML Files
  详细解决方案

跟小弟我一起学Mybatis之(四)-Mapper XML Files

热度:747   发布时间:2014-02-14 17:55:42.0
跟我一起学Mybatis之(四)----Mapper XML Files

文章中在这块之前还有一大块东西---Configuration XML,详细介绍了Mybatis的配置文件中的结构及其元素,但是这里我感觉新手还是比较注重学习应用,因此,我也是把配置文件的介绍详细看了一下,也没有做太多的实践查看效果操作,也不多做介绍。给大家推荐一个链接:http://mybatis.github.io/mybatis-3/, 这里面有Mybatis的文档的翻译,而且有多国语言,虽然有些地方没有翻译,但是个人感觉已经是很不错了,确实下了很大功夫,先对这位仁兄致谢 !

?

言归正传,回到我的主题酷,下面是说到了Mapper XML Files,主要介绍的就是大家最关注的应用部分。

这篇文章先大概介绍一下Mapper XML Files中的内容,下一个详细介绍使用。

原文:The true power of MyBatis is in the Mapped Statements. This is where the magic happens. For all

? ? ? ? ? ? ?Mybatis的真正魅力所在便是映射声明。 ? ? ? ? ? ? ? ? ? ? ? ? ? 这里是奇迹发生的地方。 ? ? ? ? ? ? ? ?相对于

of?their power, the Mapper XML files are relatively simple. Certainly if you were to compare them to the

他所有的力量,Mapper XML文件时相当的简单的。 ? ? ? ? ? ? ?当然,如果你是拿它和同等意义的JDBC代码

equivalent JDBC code, you would immediately see a savings of 95% of the code. MyBatis was built

来比较的话, ? ? ? ? ? ? ? ? ?你一下子就能够看到节省了95%的代码量。 ? ? ? ? ? ? ? ? ? ? ? ? MyBatis的存在 ?

to focus on the SQL, and does its best to stay out of your way.

是为了聚焦于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——关联到另一个命名空间的缓存配置

? 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——映射插入语句。

? update– A mapped UPDATE statement.

? update——映射更新语句。

? delete– A mapped DELETE statement.

? delete——映射删除语句。

? select– A mapped SELECT statement.

? select——映射查询语句。

The next sections will describe each of these elements in detail, starting with the statements

themselves.

? 下一部分将从语句本身自己开始详细的介绍每一个元素。

?

?

注:翻译的时候有些我自己完全不知道怎么翻译的地方我参考了:http://mybatis.github.io/mybatis-3/zh/index.html? 这篇翻译,但是大部分我还是按照自己的理解和风格来了,所以,请大家多多指正。

  相关解决方案