一、使用 typeAlias 和 package 配置别名
因为在开发过程中,有些类名要写好多次,在书写和修改的时候都会很麻烦,所以为了提高开发效率减少开发工作量,mybatis为我们提供了配置别名的方式来减少工作量。
1.未配置别名:StudentMapper.xml
<!--未配置别名:StudentMapper.xml-->
<select id="getAll" resultType="com.me.pojo.Student">
select id,name,email,age
from student
</select>
2.使用typeAlias配置别名:SqlMapConfig.xml
<!--使用typeAlias配置别名:SqlMapConfig.xml-->
<typeAliases>
<typeAlias type="com.me.Student" alias="student" ></typeAlias>
</typeAliases>
type属性的值是 实体类的全限定类名,alias属性的值是别名,并且不再区分大小写
3.使用package配置别名:SqlMapConfig.xml
<!--使用package配置别名-->
<typeAliases>
<package name="com.me.pojo"></package>
</typeAliases>
package用于指定 需要配置别名的包,指定了包以后,该包 包含的实体类都会注册别名,并且别名就是类名,并且不再区分大小写。