![](/img/trans.png)
[英]MyBatis - getting table to object with one integer and list of integer
[英]Getting Map<Long, List<Object>> using MyBatis
這是我的方法,我需要得到一個Map<Long, List<CMBill>>
:
@Mapper
public interface CMBillMapper {
@MapKey("groupId")
Map<Long, List<CMBill>> getCMInvoicesByIdListSQL(@Param("invoiceIds") Set<Long> invoiceIds);
}
這是MyBatis xml config,它配置了這個map。
<?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>
,我需要另一個。 如何重寫我的映射器以獲得我需要的結果?
這種情況下,建議直接查詢獲取List,獲取結果集后再分組group_id。
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.