resultType是简单映射
resultMap主要是为了映射不规则字段
对于单表查询映射或多表联合查询映射来说,这两个都能达到我们的要求
如
public class User {
private int id;
private String username;
private String phone;
//此处省略get、set方法
}
一、使用resultType
<select id="findUser" parameterType="int" resultType="com.cathy.pojo.User">
select id, username,phone
from user
where id = #{id}
</select>
二、使用resultMap
<resultMap id="userRM" type="com.cathy.pojo.User">
<id property="id" column="id" />
<result property="username" column="username"/>
<result property="phone" column="phone"/>
</resultMap>
<select id="findUser" parameterType="int" resultMap="userRM">
select id, username,phone
from user
where id = #{id}
</select>