Mybatis配置-类型别名(typeAliases)

在Java中,类型别名(Type Alias)是一个用于简化某个类型的名称的方式。它在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>

 通过这个配置,可以在任何需要使用 ​domain.blog.Blog​的地方,直接使用 ​Blog​来代替。

在MyBatis中,你可以指定一个包,在这个包中,MyBatis将会搜索需要使用的Java Bean类。例如:

<typeAliases>
  <package name="domain.blog"/>
</typeAliases>

 在 ​domain.blog​包中的每个Java Bean,如果没有找到注释,将会使用非限定类名的首字母小写形式注册为别名。例如,​domain.blog.Author​会被注册为 ​author​。如果找到了 ​@Alias​注释,它的值将被用作别名。请看下面的示例:

@Alias("author")
public class Author {
    ...
}

 在MyBatis中有许多内置的类型别名,用于常见的Java类型。它们都是不区分大小写的,特别注意原始类型的特殊处理,由于其重载的名称。

Alias Mapped Type
_byte byte
_char (since 3.5.10) char
_character (since 3.5.10) char
_long long
_short short
_int int
_integer int
_double double
_float float
_boolean boolean
string String
byte Byte
char (since 3.5.10) Character
character (since 3.5.10) Character
long Long
short Short
int Integer
integer Integer
double Double
float Float
boolean Boolean
date Date
decimal BigDecimal
bigdecimal BigDecimal
biginteger BigInteger
object Object
date[] Date[]
decimal[] BigDecimal[]
bigdecimal[] BigDecimal[]
biginteger[] BigInteger[]
object[] Object[]
map Map
hashmap HashMap
list List
arraylist ArrayList
collection Collection
iterator Iterator

相关推荐

  1. Mybatis配置-类型别名typeAliases

    2023-12-16 04:06:06       54 阅读
  2. TypeScript type类型别名

    2023-12-16 04:06:06       33 阅读
  3. typescript type 类型别名详解

    2023-12-16 04:06:06       53 阅读

最近更新

  1. docker php8.1+nginx base 镜像 dockerfile 配置

    2023-12-16 04:06:06       75 阅读
  2. Could not load dynamic library ‘cudart64_100.dll‘

    2023-12-16 04:06:06       80 阅读
  3. 在Django里面运行非项目文件

    2023-12-16 04:06:06       64 阅读
  4. Python语言-面向对象

    2023-12-16 04:06:06       75 阅读

热门阅读

  1. log4j2 xml 配置文件 屏蔽 第三方 依赖包 的日志

    2023-12-16 04:06:06       51 阅读
  2. 1050 螺旋矩阵

    2023-12-16 04:06:06       54 阅读
  3. C++容器系列之list详解与应用

    2023-12-16 04:06:06       46 阅读
  4. 【matlab】

    2023-12-16 04:06:06       51 阅读
  5. 【算法】动态规划(dp问题),持续更新

    2023-12-16 04:06:06       63 阅读
  6. springboot实战之oss上传工具封装

    2023-12-16 04:06:06       53 阅读
  7. 重新格式化字符串

    2023-12-16 04:06:06       52 阅读
  8. 37、池化与卷积的区别

    2023-12-16 04:06:06       47 阅读
  9. 记录 | ubuntu安装Albert

    2023-12-16 04:06:06       49 阅读