数据库:套餐(Setmeal)包含检查组(CheckGroup),检查组包含检查项(CheckItem)
column为数据库查询字段别名,不可以重复;property为实体类中定义的属性
<resultMap id="baseResultMap" type="com.baidu.pojo.Setmeal">
<id column="setmeal_id" property="id"/>
<result column="setmeal_name" property="name"/>
<result column="setmeal_sex" property="sex"/>
<result column="setmeal_age" property="age"/>
<result column="setmeal_remark" property="remark"/>
<!--套餐与检查组多对多映射-->
<collection property="checkGroups" ofType="com.baidu.pojo.CheckGroup">
<id column="checkgroup_id" property="id"/>
<result column="checkgroup_name" property="name"/>
<result column="checkgroup_code" property="code"/>
<!--检查组与检查项多对多映射-->
<collection property="checkItems" ofType="com.baidu.pojo.CheckItem">
<id column="checkitem_id" property="id"/>
<result column="checkitem_name" property="name"/>
<result column="checkitem_code" property="code"/>
<result column="checkitem_sex" property="sex"/>
<result column="checkitem_age" property="age"/>
</collection>
</collection>
</resultMap>
<!--根据套餐ID查询套餐详情(包含套餐基本信息、检查组信息、检查项信息)-->
<select id="SelectById" parameterType="int" resultMap="baseResultMap">
select t_setmeal.id setmeal_id,t_setmeal.name setmeal_name,t_setmeal.age setmeal_age,t_setmeal.sex setmeal_sex,t_setmeal.remark setmeal_remark,t_setmeal.img setmeal_img,
t_checkgroup.id checkgroup_id,t_checkgroup.name checkgroup_name,t_checkgroup.remark checkgroup_remark,t_checkitem.id checkitem_id,t_checkitem.name checkitem_name
from t_setmeal
left join t_setmeal_checkgroup on t_setmeal.id = t_setmeal_checkgroup.setmeal_id
left join t_checkgroup on t_setmeal_checkgroup.checkgroup_id = t_checkgroup.id
left join t_checkgroup_checkitem on t_checkgroup_checkitem.checkgroup_id = t_checkgroup.id
left join t_checkitem on t_checkitem.id = t_checkgroup_checkitem.checkitem_id
where t_setmeal.id = #{id}
</select>