原始数据:
SHOP_ID | ACCOUNT_ID |
2 | 192 |
2 | 193 |
需求是:根据店铺id获取店员帐号列表
mybatis配置代码:
<resultMap class="java.util.HashMap" id="AccountMap" groupBy="shopId">
<result column="SHOP_ID" property="shopId" jdbcType="BIGINT" />
<result property="accountList" javaType="java.util.ArrayList" resultMap="SHOP_ACCOUNT_REF.accountResult" />
</resultMap>
<resultMap id="accountResult" class="java.lang.Long">
<result column="ACCOUNT_ID" property="accountId" jdbcType="BIGINT" />
</resultMap>
<!-- 提供给IM的接口:根据店铺id获取店铺帐号列表-->
<select id="selectAccountIdsByShopId" resultMap="AccountMap" parameterClass="list">
select SHOP_ID,ACCOUNT_ID from SHOP_ACCOUNT_REF
where IS_DEL=0 and SHOP_ID in
<iterate open="(" close=")" conjunction="," >
#[]#
</iterate>
</select>
上面代码中shopId是key,accountList是value.
dao操作代码:
public HashMap<Long, List<Long>> selectAccountIdsByShopId(List<Long> shopIds)
throws DataAccessException {
return (HashMap<Long, List<Long>>)sqlMapClient.queryForMap("SHOP_ACCOUNT_REF.selectAccountIdsByShopId", shopIds, "shopId","accountList");
}