1、返回简单数据类型
int double long String
2、返回POJO数据类型
返回User对象类型
3、resultMap结果类型
resultType可以指定pojo将查询结果映射为pojo,但需要pojo的属性名和sql查询的列名一致方可映射成功。
如果sql查询字段名和pojo的属性名不一致,可以通过resultMap将字段名和属性名作一个对应关系 ,resultMap实质上还需要将查询结果映射到pojo对象中。
resultMap可以实现将查询结果映射为复杂类型的pojo,比如在查询结果映射对象中包括pojo和list实现一对一查询和一对多查询。
<!--演示resultMap配置-->
<select id="findUsers" resultMap="userMap">
select id _id,username _username,birthday _birthday,sex _sex,address _address from user
</select>
<!--
配置resultMap,用来进行数据封装
id="唯一的名称,用来被引用的"
type="进行封装数据的类型"
-->
<resultMap id="userMap" type="cn.domain.User">
<!--
property="JavaBean中的属性"
column="表中的字段"
-->
<result property="id" column="_id"/>
<result property="username" column="_username" />
<result property="birthday" column="_birthday" />
<result property="sex" column="_sex" />
<result property="address" column="_address" />
</resultMap>