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的引用。
例子也可以看上面代碼。