resultType: 当使用resultType做SQL语句返回结果类型处理时,对于SQL语句查询出的字段在相应的pojo中必须有和它相同的字段对应,而resultType中的内容就是pojo在本项目中的位置。
举例:
此时我选择出来的Datainfo整张表就可以对应com.cloud.pojo.Datainfo,的一对一关系。
<select id="selectByUserId" parameterType="java.lang.Integer" resultType="com.cloud.pojo.Datainfo">
select datainfo.* from datainfo,user,collect where datainfo.id=collect.id and collect.user_id=#{userId,jdbcType=INTEGER};
</select>
resultMap: 当使用resultMap做SQL语句返回结果类型处理时,通常需要在mapper.xml中定义resultMap进行pojo和相应表字段的对应。
举例:
此时我使用resultMap,我们需要自己写上边这部分,也就是让表中的列对应实体类的属性。
<resultMap id="BaseResultMap" type="com.cloud.pojo.Collect">
<id column="collect_id" jdbcType="INTEGER" property="collectId" />
<result column="user_id" jdbcType="INTEGER" property="userId" />
<result column="group_id" jdbcType="INTEGER" property="groupId" />
<result column="id" jdbcType="VARCHAR" property="id" />
</resultMap>
<select id="selectByPrimaryKey" parameterType="java.lang.Integer" resultMap="BaseResultMap">
select
<include refid="Base_Column_List" />
from collect
where collect_id = #{collectId,jdbcType=INTEGER}
</select>