mybatis返回HashMap

原始數據:

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");
	}




發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章