软件编程
位置:首页>> 软件编程>> java编程>> mybatis 查询返回Map<String,Object>类型

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

作者:菜鸟笔记  发布时间:2023-11-14 07:06:09 

标签:mybatis,返回,Map类型

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>

返回结果如下:

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

来源:https://xingfeiyin.blog.csdn.net/article/details/123738647

0
投稿

猜你喜欢

手机版 软件编程 asp之家 www.aspxhome.com