MyBatis配置项--typeAliases

类型别名是为java类型设置一个短的名字。只和XML配置有关,存在的意义仅在于用来减少类完全限定名的冗余。

例如:

<typeAliases>

  <typeAlias alias="Author" type="domain.blog.Author"/>

  <typeAlias alias="Blog" type="domain.blog.Blog"/>

  <typeAlias alias="Comment" type="domain.blog.Comment"/>

  <typeAlias alias="Post" type="domain.blog.Post"/>

  <typeAlias alias="Section" type="domain.blog.Section"/>

  <typeAlias alias="Tag" type="domain.blog.Tag"/>

</typeAliases>

当这样配置时,Blog可以用在任何使用domain.blog.Blog的地方。

也可以指定一个包名,MyBatis会在包名下面搜索需要的Java Bean,比如:

<typeAliases>

  <package name="domain.blog"/>

</typeAliases>

每一个在包domin.blog中的Java Bean,在没有注解的情况下,会使用Bean的首字母小写的非限定类名来作为它的别名。比如domain.blog.Author的别名为author;若有注解,则别名为注解值。看如下例子:

@Alias("author")

public class Author {

    ...

}

 

下面是一些常见的java类型内建的相应的类型别名。它们都是大小写不敏感的,需要注意的是由基本类型名称重复导致的特殊处理。

别名

映射的类型

别名

映射的类型

别名

映射的类型

_byte

byte

byte

Byte

decimal

BigDecimal

_long

long

long

Long

bigdecimal

BigDecimal

_short

short

short

Short

object

Object

_int

int

int

Int

map

Map

_integer

integer

integer

Integer

hashmap

HashMap

_double

double

double

Double

list

List

_float

float

float

Float

arraylist

ArrayList

_boolean

boolean

boolean

Boolean

collection

Collection

string

String

date

Date

iterator

Iterator

原文地址:https://www.cnblogs.com/arrows/p/10338466.html