MyBatis with Guava multimap

萝らか妹 提交于 2019-12-12 09:04:56

问题


I want to use Guava multimap as a resultMap with MyBatis, to return a resultset that has a collection of several one to many entries, but I am not able to figure out the exact syntax for the same. Below is a sample of my table :

+----+---------+----------+-------------+
| ID | PART_ID | NAME     | PART_FAMILY |
+----+---------+----------+-------------+
|  1 |       1 | bush     |         300 |
|  2 |       1 | a-bush   |         300 |
|  3 |       1 | 300-bush |         300 |
|  4 |       2 | nut      |         301 |
+----+---------+----------+-------------+

I want a resultset such that I have a Guava multimap with PART_ID as the key, and NAME and PART_FAMILY as the result.

Ex :

Index 0 :
    Key : 1 //PART_ID
    Value : [NAME: bush, PART_FAMILY: 300]
Index 1 :
    Key : 1
    Value : [NAME: a-bush, PART_FAMILY: 300]
Index 2 :
    Key : 1
    Value : (NAME: 300-bush, PART_FAMILY: 300)  
Index 3 :
    Key : 2
    Value : (NAME: nut, PART_FAMILY: 301)   

And below is my query :

<resultMap id="partsMap" type="com.google.common.collect.Multimap">
    <id column="PART_ID" property="key" />
    //Not sure what to put here
</resultMap>

<select id="getParts" resultMap="partsMap">
    SELECT 
    PART_ID, NAME, PART_FAMILY
    FROM PART_NAMES
    WHERE ${filter}
    ORDER BY PART_ID
</select>

I wanted help with the below points :

  1. Can mybatis return the a resultMap in a Guava MultiMap as per what I have described above?
  2. If yes, can you please help me with the syntax for the same?
  3. If no, then how can I obtain the resultset as mentioned in the example?

Thanks in advance!

来源:https://stackoverflow.com/questions/43321454/mybatis-with-guava-multimap

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!