MyBatis中为实体类起别名

1.为某一个实体类起别名通过typeAliases标签

 <!--给实体类设置别名-->
    <typeAliases>
        <typeAlias type="com.lqq.entity.User" alias="user"/>
			//这是给具体的某一个实体类起别名
    </typeAliases>

在实现类的xml中,引用的类型不再是全类名,可以为别名

    <select id="findUserById" resultType="user">
    select * from t_user where id =#{id}
  </select>

2.给一整个包下的实体类都起别名

  <typeAliases>
        <package name="com.lqq.entity"/>
        //给一个包下的实体类都起别名,默认的别名为首字母小写
    </typeAliases>
 <select id="findUserById" resultType="user">
    select * from t_user where id =#{id}
  </select>

可以通过注解@Alias修改默认的别名
MyBatis已经把一些常见的Bean注册了别名
list
set
map
array

你可能感兴趣的:(mybatis,类)