您的位置:首页 > 其它

mybatis-全局配置文件-mybatis-config.xml- typeAliases-5

2017-06-07 10:37 661 查看
为类起别名,如果觉得

EmployeeMapper.xml,resultType写全类名过长的话:

但是推荐写全类名

<mapper namespace="com.stayreal.mybatis.EmployeeMapper">
<select id="getEmpById" resultType="com.stayreal.mybatis.Employee">
select * from tbl_employee where id = #{id}
</select>
<mapper>


三种方式

mybatis-config.xml

<typeAliases>
<!-- 为某个java类型起别名
type:要起别名类型的全类名;默认别名就是类名小写,employee
alias:指定新的别名 别名不区分大小写
-->
<!--<typeAlias type="com.stayreal.mybatis.Employee"  />-->
<!--<typeAlias type="com.stayreal.mybatis.Employee"  alias="emp"/>-->
<!-- 批量起别名:为某个包下的所有类批量起别名
name:指定包名(为当前包及所有下面的后代包每个类起一个默认别名(默认类名小写))
-->
<package name="com.stayreal.mybatis"/>
<!-- 可以使用@Alias("emp")注解起别名 在类上面添加  注意是在有包扫描的情况下-->
<!-- 包扫描 <package name="com.stayreal.mybatis"/>-->
</typeAliases>
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签:  mybatis