首页 > 其他 > 详细

mybatis类型别名

时间:2018-12-31 18:44:33      阅读:300      评论:0      收藏:0      [点我收藏+]

在mybatis中,statement的parameterType指定了输入参数的类型,resultType指定了输出结果的映射类型
可以针对parameterType或resultType中指定的类型,在<typeAliases>中定义别名,然后在parameterType或resultType中使用定义的别名


1:单个别名定义
1):定义别名

<!--
type:类型全限定名
alias:别名
-->
<typeAlias type="org.pine.mybatis.po.User" alias="user"/>

2):使用别名
可以在parameterType或resultType中引用 1)中 已定义的别名

<!-- 根据id查询用户 -->
<select id="queryUserById" parameterType="java.lang.Integer" resultType="user">
select t.id,t.username,t.birthday,t.sex,t.address
from user t
where t.id =#{id}
</select>


2:批量别名定义
1):定义别名

<!--
name:指定 包名
mybatis会自动扫描 包名 下的Java类,自动定义别名。注意:别名就是类名(首字母大写或小写都可以)
-->
<package name="org.pine.mybatis.po"/>

2):使用别名
可以在parameterType或resultType中引用 1)中 已定义的别名

<!-- 根据id查询用户 --> <!-- resultType="User"或者resultType="user"都可以 -->
<select id="queryUserById" parameterType="java.lang.Integer" resultType="user">
select t.id,t.username,t.birthday,t.sex,t.address
from user t
where t.id =#{id}
</select>

mybatis类型别名

原文:https://www.cnblogs.com/thaipine/p/10202405.html

(0)
(0)
   
举报
评论 一句话评论(0
关于我们 - 联系我们 - 留言反馈 - 联系我们:wmxa8@hotmail.com
© 2014 bubuko.com 版权所有
打开技术之扣,分享程序人生!