Mybatis 返回Map(id,javabean)

当我们再查询数据的时候,有时候需要返回map<id,javabean>类型,这个时候,只需要正常的映射后,

添加

@MapKey("XXXXX")

注解就可以

具体操作:

1、xml编写sql

<select id="getPerson" resultMap="BaseResultMap">

        select * from t_user 

</select>

2、xml编写BaseResultMaP

<resultMap id="BaseResultMap" type="com.test.User">
        <id column="id" property="id" />
        <result column="name" property="name" />
        <result column="age" property="age" />
       
</resultMap>

3、mapper添加注解
 

@Mapper
public interface UsertMapper {

    @MapKey("id")
    Map<String, User> getUser();
}
发布了19 篇原创文章 · 获赞 5 · 访问量 4万+

猜你喜欢

转载自blog.csdn.net/weixin_42165041/article/details/104691592
今日推荐