Mapper.xml文件:
<resultMap id="VideoDetailResultMap" type="Video">
<id column="id" jdbcType="INTEGER" property="id"/>
<result column="title" jdbcType="VARCHAR" property="title"/>
<result column="detail" jdbcType="VARCHAR" property="id"/>
<result column="cover_img" jdbcType="VARCHAR" property="coverImg"/>
<result column="price" jdbcType="INTEGER" property="price"/>
<result column="point" jdbcType="DOUBLE" property="point"/>
<collection property="chapterList" ofType="Chapter">
<id column="chapter_id" jdbcType="INTEGER" property="id"/>
<result column="chapter_title" jdbcType="VARCHAR" property="title"/>
<result column="ordered" jdbcType="INTEGER" property="ordered"/>
<result column="chapter_create_time" jdbcType="TIMESTAMP" property="createTime"/>
<collection property="episodeList" ofType="Episode">
<id column="episode_id" jdbcType="INTEGER" property="id"/>
<result column="episode_title" jdbcType="VARCHAR" property="title"/>
<result column="free" jdbcType="INTEGER" property="free"/>
<result column="num" jdbcType="INTEGER" property="num"/>
<result column="episode_ordered" jdbcType="INTEGER" property="ordered"/>
<result column="episode_create_time" jdbcType="TIMESTAMP" property="createTime"/>
<result column="play_url" jdbcType="VARCHAR" property="playUrl"/>
</collection>
</collection>
</resultMap>
<select id="findDetailById" resultMap="VideoDetailResultMap">
SELECT
v.id,v.title,v.detail,v.cover_img,v.price,v.point,
c.id as chapter_id,c.title as chapter_title,c.ordered,c.creat_time as chapter_create_time,
e.id as episode_id,e.title as episode_title,e.free,e.num,e.ordered as episode_ordered,e.creat_time as episode_create_time,e.play_url
from video v
left JOIN chapter c ON v.id = c.video_id
LEFT JOIN episode e ON c.id = e.chapter_id
WHERE v.id = #{video_id}
ORDER BY c.ordered,num ASC
</select>