在mybatis-config.xml文件中使用typeAliases标签来起别名
<typeAliases>
<typeAlias type="com.powernode.mybatis.pojo.Car" alias="Car"/>
</typeAliases>Car 作为 com.wsd.mybatis.pojo.Car 的别名,在mapper.xml 映射文件中的resultType="com.wsd.mybatis.pojo.Car"
就可以简写为resultType="Car"
alias是大小写不敏感的。也就是说假设alias="Car",再用的时候,可以CAR,也可以car,也可以Car,都行。
alias属性不是必须的,如果缺省的话,type属性指定的类型名的简类名作为别名。
<typeAliases>
<typeAlias type="com.powernode.mybatis.pojo.Car" />
</typeAliases>没有指定 alias ,那么 默认 alias=Car (类的simpleName )
package 方式:
如果一个包下的类太多,每个类都要起别名,会导致typeAlias标签配置较多,所以mybatis用提供package的配置方式,只需要指定包名,该包下的所有类都自动起别名,别名就是简类名。并且别名不区分大小写
<typeAliases>
<package name="com.powernode.mybatis.pojo"/>
</typeAliases>com.powernode.mybatis.pojo 包下的所有类都被起了别名,别名是 类的 simpleName
namespace 不能使用别名