mybatis的mapper返回map结果集

mybatis系列

通过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.xixicat.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
        from user_info
</select>
阅读 32k

推荐阅读
code-craft
用户专栏

spring boot , docker and so on 欢迎关注微信公众号: geek_luandun

705 人关注
1805 篇文章
专栏主页