在mybatis-config,xml中配置别名的方法:

顺序规定

The content of element type “configuration” must match “(properties?,settings?,typeAliases?,typeHandlers?,objectFactory?,objectWrapperFactory?,reflectorFactory?,plugins?,environments?,databaseIdProvider?,mappers?)”.

typeAliases需按顺序放在指定位置,即按上述顺序,位于setting后

用法1:使用alias=“name”,这样即将type对应的类映射为 name了,如下图,即可在mybatis里面用abc替换top.l50.work5.pojo.Student
1
2
3
4
5
<!--别名用法-->
    <typeAliases>
        <typeAlias alias="abc" type="top.l50.work5.pojo.Student"/>
    </typeAliases>
<!--别名用法-->
用法2:只使用type=,这时候默认的别名就是这个属性的类名,且不区分大小写,如下图,可采用(Student或student代替top.l50.work5.pojo.Student)
1
2
3
4
5
<!--别名用法-->
<typeAliases>
    <typeAlias type="top.l50.work5.pojo.Student"/>
</typeAliases>
<!--别名用法-->

(不常用)也可将两种混合使用

用法3:使用package name参数
1
2
3
4
5
    <typeAliases>
<!--        通过包来设置类型别名-->
        <package name="top.l50.mybatis.pojo"/>
<!--        指定包下所有类型都将具有默认别名即类名也不区分大小写-->
    </typeAliases>