创建别名的三种方法
- 给实体类起别名
<typeAliases>
<typeAlias type="com.pjx.pojo.User" alias="UserDao"/>
</typeAliases>
- 指定的一个包名,则包下的类名首字母小写作为别名
<typeAliases>
<package name="com.pjx.pojo"/>
</typeAliases>
使用注解更改别名:
@Alias()
在使用中可用“别名”代替原名
如:
<select id="selectUser" resultType="com.pjx.UserDao" >
select * from user
</select>
可更改为:
<select id="selectUser" resultType="user" >
select * from user
</select>
总结:实体类少使用第一种,实体类多使用第二种。第二种如果要改别名需要使用注解
一些默认的别名
下面是一些为常见的 Java 类型内建的类型别名。它们都是不区分大小写的,注意,为了应对原始类型的命名重复,采取了特殊的命名风格。
别名 映射的类型
_byte byte
_long long
_short short
_int int
_integer int
_double double
_float float
_boolean boolean
string String
byte Byte
long Long
short Short
int Integer
integer Integer
double Double
float Float
boolean Boolean
date Date
decimal BigDecimal
bigdecimal BigDecimal
object Object
map Map
hashmap HashMap
list List
arraylist ArrayList
collection Collection
iterator Iterator