1

这是我的方法,我需要得到一个Map<Long, List<CMBill>>

@Mapper
public interface CMBillMapper {

    @MapKey("groupId")
    Map<Long, List<CMBill>> getCMInvoicesByIdListSQL(@Param("invoiceIds") Set<Long> invoiceIds);
}

这是 MyBatis xml config,用于配置此地图。

<?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="ru.example.CMBillMapper">
    <resultMap id="CMBillResult" type="CMBill">
        <result property="id" column="id"/>
        <result property="groupId" column="group_id"/>
        <result property="clientId" column="client_id"/>
        <result property="paidAmount" column="paid_amount"/>
        <result property="amount" column="amount"/>
        <result property="currency" column="currency"/>
        <result property="status" column="status"/>
    </resultMap>
    <select id="getCMInvoicesByIdListSQL" resultMap="CMBillResult">
        select it.group_id    as group_id,
               it.id          as id,
               it.client_id   as receiver_id,
               it.status      as invoice_status,
               it.amount      as amount,
               it.currency    as currency,
               it.paid_amount as paid_amount,
               if.type        as if_type,
               if.code        as if_code,
               if.val         as if_val
        from cm_invoice_tab it
                 left join cm_inv_group_field_tab if
                           on if.group_id = it.group_id
        where it.group_id in (#{invoiceIds})
    </select>
</mapper>

但是 mapper 的结果是Map<Long, CMBill>,我需要另一个。如何重写我的映射器以获得我需要的结果?

4

1 回答 1

0

这种情况下,建议直接查询获取List,获取结果集后再分组group_id。

于 2020-05-19T08:51:09.087 回答