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.
typeAliases
-
typeAlias:为某个java类型起别名
- type:指定要起别名的类型全类名;默认别名就是类名小写;employee
- alias:指定新的别名
起别名
配置文件:
<typeAliases><typeAlias type="com.atguigu.mybatis.bean.Employee"></typeAlias></typeAliases>
映射文件:
<select id="getEmpById" resultType="employee">select id,last_name,email,gender from tb1_employee where id = #{id}</select>
配置文件:
<select id="getEmpById" resultType="emp">select id,last_name,email,gender from tb1_employee where id = #{id}</select>
映射文件:
<typeAliases><typeAlias type="com.atguigu.mybatis.bean.Employee" alias="emp"></typeAlias></typeAliases>
批量起别名
-
package:为某个包下的所有类批量起别名
-
name:指定包名(为当前包以及下面所有的后代包的每一个类都起一个默认别名(类名小写))
-
注:别名不区分大小写
<typeAliases><package name="com.atguigu.mybatis.bean"/></typeAliases>
Alias
- 批量起别名的情况下,使用@Alias注解为某个类型指定新的别名