实体类设置别名(typeAliases)

Exisi 2021-03-27 07:11:02
Categories: Tags:

 

 

 

 

使用完整包名

<select id="getUserById" parameterType="int" resultType="com.mybatis.pojo.Users">
        select * from smbms_user where id=#{id}
</select>

 

 

 

使用实体类的 typeAlias 别名

 

<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE configuration PUBLIC "-//mybatis.org//DTD Config 3.0//EN" "http://mybatis.org/dtd/mybatis-3-config.dtd">

 

<configuration>

 

 

 

<!-- 设置实体类别名 -->

<typeAliases>

<typeAlias type="com.mybatis.pojo.Users" alias="Users"/>

</typeAliases>

 

</configuration>

 

 

 

<?xml version="1.0" encoding="UTF-8" ?>
<!DOCTYPE mapper PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN" "http://mybatis.org/dtd/mybatis-3-mapper.dtd">


<mapper namespace="com.mybatis.dao.UsersMapper">

 

 

<select id="getUserById" parameterType="int" resultType="Users">
        select * from smbms_user where id=#{id}
</select>

</mapper>

 

 

 

 

使用包名作为别名

 

<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE configuration PUBLIC "-//mybatis.org//DTD Config 3.0//EN" "http://mybatis.org/dtd/mybatis-3-config.dtd">

 

 

<configuration>

 

    <!-- 设置实体类别名 -->

    <typeAliases>

    <package name="com.mybatis.pojo.Users" />

    </typeAliases>

 

</configuration>

 

 

 

<?xml version="1.0" encoding="UTF-8" ?>
<!DOCTYPE mapper PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN" "http://mybatis.org/dtd/mybatis-3-mapper.dtd">


<mapper namespace="com.mybatis.dao.UsersMapper">

 

<select id="getUserById" parameterType="int" resultType="Users">
        select * from smbms_user where id=#{id}
</select>

</mapper>