javaType和ofType
当使用反向查询select从另一个maper文件中取出数据时必须用ofType
<select id="GetClassInfo" parameterType="int" resultMap="GetClassMap">
select * from class c ,student s,teacher t where c.teacher_id=t.t_id and c.c_id = s.class_id and c.c_id=#{id}
</select>
<!-- 根据班级id查找学生信息,一对多联表查询(1个班级N个学生) -->
<resultMap type="jike.book.pojo.Classes" id="GetClassMap">
<id property="id" column="c_id" />
<result property="name" column="c_name" />
<association property="teacher" column="teacher_id" javaType="jike.book.pojo.Teacher">
<id property="id" column="t_id"/>
<result property="name" column="t_name"/>
</association>
<collection property="StuList" ofType="jike.book.pojo.Student">
<id property="id" column="s_id"/>
<result property="name" column="s_name" />
</collection>
</resultMap>
resultType和resultMap
resultType是MyBatis直接封装好并以对应类型直接返回,而resultMap则是对外部ResultMap的引用。
例子也可以看上面代码。