<?xml version="1.0" encoding="UTF-8" ?>
<!DOCTYPE mapper
        PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN"
        "http://mybatis.org/dtd/mybatis-3-mapper.dtd">
<!--namespace 命名空间-->
<mapper namespace="com.sf.mapper.OneToManyMapper">
    <resultMap id="oneToMany" type="classes">
        <id column="cid" property="id"/>
        <result column="cname" property="name"/>
        <!--
        一对多关系
        collection 标签 用来配置被包含的集合对象的映射关系
            ofType属性 指定被包含的对象的集合中对象的数据类型

        -->
        <collection property="studentList" ofType="student">
            <id column="sid" property="id"/>
            <result column="sname" property="name"/>
            <result column="age" property="age"/>
        </collection>
    </resultMap>
    <select id="selectAll" resultMap="oneToMany">
        SELECT s.id sid,s.name sname,s.age,c.id cid,c.name cname
        FROM student s,classes c
        WHERE s.cid=c.id
    </select>
</mapper>