美文网首页
Mybatis Configuration 之 TypeAlia

Mybatis Configuration 之 TypeAlia

作者: 黑曼巴yk | 来源:发表于2020-10-04 16:36 被阅读0次

TypeAliases

类型别名是为java类型设置的短名字,它只和xml配置关联且仅仅是为了减少类的完全限定名键入的冗余

<typeAliases>
  <typeAlias alias="Author" type="domain.blog.Author"/>
  <typeAlias alias="Blog" type="domain.blog.Blog"/>
</typeAliases>

mybatis默认支持的别名

image.png

代码如下,可以看到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>

相关文章

网友评论

      本文标题:Mybatis Configuration 之 TypeAlia

      本文链接:https://www.haomeiwen.com/subject/wvcfuktx.html