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. For example:

  1. <typeAliases>
  2. <typeAlias alias="Author" type="domain.blog.Author"/>
  3. <typeAlias alias="Blog" type="domain.blog.Blog"/>
  4. <typeAlias alias="Comment" type="domain.blog.Comment"/>
  5. <typeAlias alias="Post" type="domain.blog.Post"/>
  6. <typeAlias alias="Section" type="domain.blog.Section"/>
  7. <typeAlias alias="Tag" type="domain.blog.Tag"/>
  8. </typeAliases>

With this configuration, Blog can now be used anywhere that domain.blog.Blog could be.

You can also specify a package where MyBatis will search for beans. For example:

  1. <typeAliases>
  2. <package name="domain.blog"/>
  3. </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. See the example below:

  1. @Alias("author")
  2. public class Author {
  3. ...
  4. }

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.

AliasMapped Type
_bytebyte
_char (since 3.5.10)char
_character (since 3.5.10)char
_longlong
_shortshort
_intint
_integerint
_doubledouble
_floatfloat
_booleanboolean
stringString
byteByte
char (since 3.5.10)Character
character (since 3.5.10)Character
longLong
shortShort
intInteger
integerInteger
doubleDouble
floatFloat
booleanBoolean
dateDate
decimalBigDecimal
bigdecimalBigDecimal
bigintegerBigInteger
objectObject
date[]Date[]
decimal[]BigDecimal[]
bigdecimal[]BigDecimal[]
biginteger[]BigInteger[]
object[]Object[]
mapMap
hashmapHashMap
listList
arraylistArrayList
collectionCollection
iteratorIterator