mybatis 查询返回Map<String,Object>类型

2023-03-20 11:03:19 查询 返回 类型

mybatis 查询返回Map<String,Object> 类型,平时没太注意怎么用,今天又遇到了总结记录一下,方便以后处理此类问题。

Mapper.java中的方法:

@MapKey("userId")
Map<String,UserInfo> personalInfoByUserIds(List<String> list);

mapper.xml文件中的配置:

<resultMap id="BaseResultMap" type="com.*.*.entity.UserInfo">
    <id column="user_id" jdbcType="VARCHAR" property="userId" />
    <result column="user_code" jdbcType="INTEGER" property="userCode" />
    <result column="user_name" jdbcType="VARCHAR" property="userName" />
    <result column="user_gender" jdbcType="INTEGER" property="userGender" />
    <result column="mobile_phone" jdbcType="VARCHAR" property="mobilePhone" />
    <result column="birthday" jdbcType="DATE" property="birthday" />
  </resultMap>
 
 
<select id="personalInfoByUserIds" resultMap="BaseResultMap">
      select * from t_user_info i where i.user_id in
      <foreach collection="list" item="item" separator="," open="(" close=")" index="index">
        #{item}
      </foreach>
</select>

返回结果如下:

相关文章