场景
在Mybatis核心配制文件中配制延迟加载后全对所有满足延迟加载的SQL进行延迟加载操作。当某条SQL满足延迟加载条件,但又不想让其延迟加载时可以使用fetchType属性进行控制。默认情况下fetchType的值为true,表示支持延迟加载,将fetchType值改为false即可取消延迟加载。实例
StudentMapper.xml
<select id="getStudentsByClassId" resultType="com.cat.pojo.Student">
SELECT name, age, sex, class_code
FROM student
WHERE class_code = #{class_code}
</select>
ClassInfoMapper.xml
<select id="getClassAndStudentByClassID" resultMap="classAndStudentMap">
SELECT class_name, class_code
FROM class
WHERE class_id = #{class_id}
</select>
<resultMap id="classAndStudentMap" type="com.cat.pojo.ClassInfo">
<result column="class_code" property="classCode" />
<result column="class_name" property="className" />
<assosiation property="class_code" select="com.cat.mapper.StudentMapper.getStudentsByClassId" fetchType="false" />
</resultMap>
fetchType属性同样可以作用于collection标签。