体检管理系统——多表查询思路分析

套餐dao
查询思路。 首先在SetmealDao.xml根据传递的套餐的id查询出套餐的基本信息,然后套餐的基本属性的映射关系,以及套餐和检查组的多对多的映射关系,传递到CheckGroupDao.xml中信息查询套餐所对象的检查组的详细信息,

<!--套餐的基本映射-->
<resultMap id="baseMap" type="live.longmarch.pojo.Setmeal">
    <id column="id" property="id"></id>
    <result column="name" property="name"></result>
    <result column="code" property="code"></result>
    <result column="helpCode" property="helpCode"></result>
    <result column="sex" property="sex"></result>
    <result column="age" property="age"></result>
    <result column="price" property="price"></result>
    <result column="remark" property="remark"></result>
    <result column="attention" property="attention"></result>
    <result column="img" property="img"></result>
</resultMap>
<!--套餐的检查组映射-->
<resultMap id="findResultById"
           type="setmeal"
           extends="baseMap">
    <collection property="checkGroups"
                javaType="ArrayList"
                ofType="checkGroup"
                column="id"
                select="live.longmarch.dao.CheckGroupDao.findCheckGroupById">
    </collection>
</resultMap>

<!--返回套餐的信息-->
<select id="findByid" resultMap="findResultById" parameterType="int">
    select * from t_setmeal where id =#{id}
</select>

检查组dao
首先配置检查组的基本映射信息,然后配置检查组和检查项的多对多的映射关系,
在CheckGroupDao.xml首先使用内查询的方式先根据套餐的id 从中间表中查询出所有的检查组id,然后根据id查询出所有的检查组的基本信息,然后传递到检查项中根据检查组的id 查询出所对应的检查项的数据

<!--检查组的映射-->
<resultMap id="baseResultMap" type="checkGroup">
    <id column="id" property="id"></id>
    <result column="code" property="code"></result>
    <result column="name" property="name"></result>
    <result column="helpCode" property="helpCode"></result>
    <result column="sex" property="sex"></result>
    <result column="remark" property="remark"></result>
    <result column="attention" property="attention"></result>
</resultMap>

<resultMap id="findCheckGroupById" type="checkGroup" extends="baseResultMap">
    <collection property="checkItems"
                ofType="checkItem"
                javaType="ArrayList"
                column="id"
                select="live.longmarch.dao.CheckItemDao.findCheckItemById">
    </collection>
</resultMap>

<!--根据id返回套餐对应的所有的检查组数据-->
<select id="findCheckGroupById" resultMap="findCheckGroupById" parameterType="int">
SELECT * FROM t_checkgroup WHERE id IN
(SELECT checkgroup_id FROM t_setmeal_checkgroup WHERE setmeal_id = #{id});
</select>

检查项
使用内查询的方式根据传递过来的检查组的id在中间表中进行查询所对应的检查项的id ,然后根据id查询出所对应的检查项的详细信息。

<!--根据检查组id查询出所对应的所有的检查项的数据-->
<select id="findCheckItemById" resultType="live.longmarch.pojo.CheckItem" parameterType="int">
    SELECT * FROM t_checkitem WHERE id IN (
 SELECT checkitem_id FROM t_checkgroup_checkitem WHERE checkgroup_id = #{id}
    );
</select>
发布了71 篇原创文章 · 获赞 1 · 访问量 1152

猜你喜欢

转载自blog.csdn.net/weixin_44993313/article/details/103747563
今日推荐