mybatis的mapper返回map结果集

本文介绍如何使用MyBatis的@MapKey注解指定Map的key值,并展示了两个示例:一个例子中map的value为自定义的Java类,另一个例子中map的value为Map类型。同时提供了对应的XML配置文件示例。

通过MapKey指定map的key值

@MapKey("id")
Map<Long, UserInfo> getUserInfoMap();

@MapKey("id")
Map<Long, Map<String,Object>> getUserValueMap();

map的value为java类

<resultMap id="UserResultMap" type="com.xxx.domain.UserInfo">
        <result property="id" column="id" />
        <result property="username" column="username" />
        <result property="sex" column="sex" />
    </resultMap>
<select id="getUserInfoMap" resultMap="UserResultMap">
   select id,username,sex 
   from user_info
</select>

map的value为map

<select id="getUserValueMap" resultType="map" >
        select id,username,sex 
        from user_info
</select>
评论 2
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值