Mybatis一对多查询,成功案例,以及失败案例(一对多,多的一方只封装进了第一条数据)

一对多查询,关联查询方式

两个表关联查询,然后封装
<?xml version="1.0" encoding="UTF-8" ?>
<!DOCTYPE mapper PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN" "http://mybatis.org/dtd/mybatis-3-mapper.dtd">

<mapper namespace="com.xxx.biz.sys.dao.KeyRoleSourceMapper">

    <resultMap id="poolResult" type="com.xxx.biz.pool.entity.Pool">
        <result property="lobNumber" column="lob_number"/>
        <collection property="opItems" ofType="com.xxx.biz.po.entity.OPItem">
            <result property="itemPlanMember" column="ITEM_PLAN_MEMBER"/>
            <result property="planItemAmount" column="PLAN_ITEM_AMOUNT"/>
            <result property="pricingModeal" column="PRICING_MODEAL"/>
        </collection>
    </resultMap>

    <select id="queryPoolAllLobNumber" resultMap="poolResult">
        select
            source.lob_number,
            item.ITEM_PLAN_MEMBER,
            item.PLAN_ITEM_AMOUNT,
            item.PRICING_MODEAL
        from
            tbl_keyrole_source source
        left join tbl_joinitem joinitem on joinitem.lob_number = source.lob_number and joinitem.role_type = '项目经理'
        left join op_item item on item.item_no = joinitem.item_no
        where
            source.keyrole_type = 17
            and source.ignoe= 0
            and source.month_id = 1
    </select>

    <update id="updateManagementScale" parameterType="com.xxx.biz.pool.entity.Pool">
        update
            tbl_keyrole_source
        set
            TM_MAX_TEAM_SIZE = #{tmMaxTeamSize},
            TM_MAX_ITEM_AMOUNT = #{tmMaxItemAmount},
            FP_MAX_TEAM_SIZE = #{fpMaxTeamSize},
            FP_MAX_ITEM_AMOUNT = #{fpMaxItemAmount}
        where
            keyrole_type = 17
            and ignoe= 0
            and month_id = 1
            and lob_number = #{lobNumber}
    </update>
</mapper>

一对多查询,内嵌查询方式

先查询主表,然后用相关列查询从表
<resul
  • 1
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值