一.resultType
举例
dao方法:(Student是一个学生实体类)
Student selectid(Integer id);
mapper:
<select id="selectid" resultType="dao.Student">//封装的实体类的路径
select id,name from students where id=#{id}
</select>
mybatis在执行时,会先调用Student类的无参构造方法创建对象(反射),然后把数据库中列名与Student类属性名相同的列值赋给属性,赋值的的过程是通过Student类中的set方法实现的。若dao接口的返回值是List集合,mybatis会把Student的对象放入List集合中。
二.resultMap
它能自定义列名个属性名的对应关系
<resultMap id="自己命名(名字1)" type="要封装的类的路径">
//主键用id,其他用result
//column代表列名,property属性名
<id column="id" property="cid"></id>
<result column="name" property="cname"></result>
</resultMap>
<select id="selectid" resultMap="名字1">
select id,name from students where id=#{id}
</select>