Mybatis Configuration 之 TypeAlia
2020-10-04 本文已影响0人
黑曼巴yk
TypeAliases
类型别名是为java类型设置的短名字,它只和xml配置关联且仅仅是为了减少类的完全限定名键入的冗余
<typeAliases>
<typeAlias alias="Author" type="domain.blog.Author"/>
<typeAlias alias="Blog" type="domain.blog.Blog"/>
</typeAliases>
mybatis默认支持的别名

代码如下,可以看到int就是别名
<select id="selectByPrimaryKey" parameterType="java.lang.Integer" resultMap="BaseResultMap">
select user_id, name, age, create_time
from user
where user_id = #{userId,jdbcType=INTEGER}
</select>
和下面方式类似
<select id="selectByPrimaryKey" parameterType="int" resultMap="BaseResultMap">
select user_id, name, age, create_time
from user
where user_id = #{userId,jdbcType=INTEGER}
</select>
自定义别名
<!-- 别名定义 -->
<typeAliases>
<!-- 针对单个别名定义 type:类型的路径 alias:别名 -->
<typeAlias type="cn.itcast.mybatis.po.User" alias="user"/>
</typeAliases>