mybatis 改进之处

<!--StudentMapper.java-->
<select id="getStudentList" parameterType="java.util.Map" resultMap="BaseResultMap"
	select U.ID,U.NAME T.NAME teacherName  from User U,Teacher T where U.TEACHER_ID=T.ID
</select>

在ibatis中,resultMap不能是BaseResultMap,由于本查询涉及到TEACHER表并从中查到T.NAME,这个NAME值不是Student对象中的属性。所以就得有一个含有teacherName别名的并继承于 BaseResultMap的ResultMap,如: studentResultMap
<resultMap type="com.jvortex.domain.Student" id="studentResultMap" extends="BaseResultMap">
		<result column="teacherName" property="teacherName"/>
</resultMap>

当然com.jvortex.domain.Student中必需要有teacherName的Getter,Setter方法。

mybatis中则不需要再重新写一个 studentResultMap的子ResultMap,但Getter,Setter方法还是需要的。

你可能感兴趣的:(xml,ibatis)