1 Configuration Structure
- properties
- settings
- typeAliases
- typeHandlers
- objectFactory
- plugins
-
environments
- environment
- transactionManager
- dataSource
- environment
- databaseIdProvider
- mappers
2 TypeAliases
A type alias is simply a shorter name for a Java type. It's only relevant to the XML configuration and simply exists to reduce redundant typing of fully qualified classnames.
是什么:類型別名是為 Java 類型設(shè)置的短名字圣贸。它只和 XML 配置關(guān)聯(lián)且僅僅是為了減少類的完全限定名鍵入的冗余裙秋。
有兩種方式可是實(shí)現(xiàn):別名定義在 XML 中或使用注解靠娱。
2.1 TypeAlias in XML
<typeAliases>
<typeAlias alias="Author" type="domain.blog.Author"/>
<typeAlias alias="Blog" type="domain.blog.Blog"/>
</typeAliases>
With this configuration, Blog can now be used anywhere that domain.blog.Blog could be.
通過這樣的配置蚌讼,Blog 就可以在 domain.blog.Blog 要存在的任何地方使用。
2.2 Set by Annotation
You can also specify a package where MyBatis will search for beans.
你也可以指定一個(gè)包名端礼,Mybatis 會(huì)在該包下搜索 Java bean括饶。
<typeAliases>
<package name="domain.blog"/>
</typeAliases>
Each bean found in domain.blog , if no annotation is found, will be registered as an alias using uncapitalized non-qualified class name of the bean. That is domain.blog.Author will be registered as author. If the @Alias annotation is found its value will be used as an alias.
每個(gè)在包 domain.blog 下發(fā)現(xiàn)的 bean,如果沒有注解恕洲,會(huì)將該 bean 的首字母小寫的非限定類名作為別名塔橡。比如 domain.blog.Author 的別名為 author。如果有 @Alias 注解霜第,它的值會(huì)被作為別名葛家。
@Alias("author")
public class Author {
...
}
附:內(nèi)置基本類型別名
There are many built-in type aliases for common Java types. They are all case insensitive, note the special handling of primitives due to the overloaded names.
有一些內(nèi)置的 Java 基本類型的別名。它們是大小寫不敏感的泌类,需要注意的是由基本類型名稱重復(fù)導(dǎo)致的特殊處理癞谒。
最后
說明:MyBatis 官網(wǎng)提供了簡體中文的翻譯,但個(gè)人覺得較為生硬刃榨,甚至有些地方邏輯不通弹砚,于是自己一個(gè)個(gè)重新敲著翻譯的(都不知道哪里來的自信...),有些地方同官網(wǎng)翻譯有出入枢希,有些倔強(qiáng)地保留了自己的迅栅,有的實(shí)在別扭則保留了官網(wǎng)的,這些都會(huì)在實(shí)踐中一一更正晴玖。鑒于個(gè)人英文能力有限读存,文章中保留了官方文檔原英文介紹(個(gè)別地方加以調(diào)整修剪)为流,希望有緣看到這里的朋友們能夠有自己的理解,不會(huì)被我可能錯(cuò)誤或不合理的翻譯帶跑偏(〃'▽'〃)让簿,歡迎指正敬察!
當(dāng)前版本:mybatis-3.5.0
官網(wǎng)文檔:MyBatis
官網(wǎng)翻譯:MyBatis 簡體中文
項(xiàng)目實(shí)踐:MyBatis Learn