这种情况前面的字段会覆盖后面的字段,所以要相同的部分需要起一个别名,以分辨
<!--关联查询-->
<!--映射关系-->
<resultMap type="com.linanjun.DTO.C1118OneToMany" id="CourseMap1">
<result property="id" column="id" jdbcType="INTEGER"/>
<result property="name" column="name" jdbcType="VARCHAR"/>
<result property="content" column="content" jdbcType="VARCHAR"/>
<!--一对多的关系 ofType泛型的地址-->
<collection property="student1118List" javaType="java.util.List"
ofType="com.linanjun.entity.Student1118">
<!--取了别名后的id和name-->
<id property="id" column="sid" />
<result property="name" column="sname" />
<result property="sex" column="sex" />
<result property="age" column="age"/>
<result property="address" column="address" />
<result property="courseId" column="course_Id"/>
</collection>
</resultMap>
<select id="selectOneToMany" resultMap="CourseMap1">
<!--s中的id,和name和c中的id,name相同,所以起了一个别名才能查询-->
select c.id,c.name,c.content,s.id sid,s.name sname,s.sex,s.age,s.address,s.course_id
from c1118 c
LEFT JOIN student1118 s
On c.id=s.course_Id
WHERE c.id=#{id}
</select>