对象之间的关系:shop存在user对象的引用, user对象中存在orders的集合。
表之间的关系:shop表中存在userid ,orders表中存在userid。
mapper.xml文件
<!-- 多级查询的resultmap -->
<resultMap type="Shop" id="shop">
<result property="shopName" column="shopname"/>
<collection property="user" ofType="User">
<id property="id" column="userid" />
<result property="username" column="username" />
<result property="sex" column="sex" />
<result property="birthday" column="birthday" />
<result property="address" column="address" />
<collection property="ordersList" ofType="Orders">
<id property="id" column="orderid" />
<result property="number" column="number" />
<result property="createtime" column="createtime" />
<result property="note" column="note" />
</collection>
</collection>
<!-- 测试多级查询的使用 -->
<select id="testSelect" resultMap="shop">
SELECT
s.shopname,
t.*
FROM
shop s
LEFT JOIN (
SELECT
u.id AS userid,
u.username,
u.birthday,
u.sex,
u.address,
o.id AS orderid,
o.number,
o.CREATEtime,
o.note
FROM
USER u
LEFT JOIN orders o ON o.user_id = u.id
) AS t ON s.userid = t.userid
</select>