mybatis嵌套查询

本文详细解析了MyBatis中单词选项映射的实现方式,包括如何使用 resultMap 定义单词及其选项的复杂关联关系,以及通过 SQL 查询语句从多个表中联表获取数据的具体操作。

摘要生成于 C知道 ,由 DeepSeek-R1 满血版支持, 前往体验 >

<!--单词选项,嵌套-->
    <resultMap id="wordAndOption" type="org.springblade.english.vo.WordAndOptionVO">
        <result column="id" property="id"/>
        <result column="en_text" property="enText"/>
        <result column="ch_text" property="chText"/>
        <result column="symbol" property="symbol"/>
        <result column="word_usage" property="wordUsage"/>
        <result column="sound_url" property="soundUrl"/>
        <collection property="wordOptions" javaType="list" ofType="org.springblade.english.vo.WordOptionVO">
            <result column="oid" property="id"/>
            <result column="word_id" property="wordId"/>
            <result column="type" property="type"/>
            <result column="text" property="text"/>
            <result column="source_url" property="sourceUrl"/>
            <result column="is_right" property="isRight"/>
        </collection>
    </resultMap>
    <!--根据年级查询该年级对应的-->
    <select id="selectWordAndOption" resultMap="wordAndOption" parameterType="java.lang.Integer">
        select a.id,a.en_text,a.ch_text,a.symbol,a.word_usage,a.sound_url,
            d.id oid, d.word_id,d.type, d.text, d.source_url, d.is_right
        from
           en_word a
        left join en_material_unit b on a.unit_id = b.id
        left join en_material c on b.material_id = c.id
        left join en_word_option d on a.id = d.word_id
        where a.is_deleted = 0 and b.is_deleted = 0 and c.is_deleted = 0 and d.is_deleted = 0 and d.type = 1
        and c.grade_id = #{grade}
    </select>
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值