将org.ec.entity.Student的别名设置成a,这样每次使用org.ec.entity.Student的时候使用a就更简便了。
<insert id="insertStudent" parameterType="org.ec.entity.Student">
insert into studentMybatis(stuNo,stuName,stuAge)
values(#{stuNo},#{stuName},#{stuAge})
</insert>
别名都在config.xml文件中设置,别名设置后在mapper.xml文件中使用忽略大小写。
1、设置单个别名
//config.xml
<configuration>
<!-- 设置单个/多个别名 -->
<typeAliases>
<!-- 单个别名 -->
<typeAlias type="org.ec.entity.Student" alias="Student"/>
</typeAliases>
...
...
</configuration>
//mapper.xml
<select id="selectAllStudent" resultType="Student">//student中的字母可大写可小写,(STudent...)
select * from studentMybatis
</select>
2、批量设置别名
自动将该包中的所有类批量定义别名,别名就是类名(不带包路径名的类名)。
//config.xml
<configuration>
<typeAliases>
<!-- 批量定义别名 -->
<package name="org.ec.entity"/>
</typeAliases>
...
...
</configuration>
<select id="selectAllStudent" resultType="sTuDent">//忽略大小写
select * from studentMybatis
</select>