MapValue annotation

64 views
Skip to first unread message

黄敏

unread,
Apr 10, 2023, 9:55:03 AM4/10/23
to mybatis-user

I want to be able to define the value of the map in addition to the key of the map, Implemented through the MapValue annotation, And it doesn't affect the original MapKey annotation

黄敏

unread,
Apr 12, 2023, 7:49:53 AM4/12/23
to mybatis-user

黄敏

unread,
May 7, 2023, 7:07:55 AM5/7/23
to mybatis-user

use it like this



```java
public interface NoticeMapper {

  @MapKey("status")
  @MapValue("count")
  Map<Integer, Integer> groupStatus();


}
```


```xml
<mapper namespace="org.apache.ibatis.submitted.mapkey_value.NoticeMapper">



  <resultMap id="groupStatusMap" type="hashmap">
    <result column="count" javaType="Integer" property="count"/>
    <result column="status" javaType="Integer" property="status"/>
  </resultMap>


  <select id="groupStatus" resultMap="groupStatusMap">
  select count(*) as count , status
    from notice group by status
  </select>



</mapper>
```
Reply all
Reply to author
Forward
0 new messages