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 :
- Can mybatis return the a resultMap in a Guava MultiMap as per what I have described above?
- If yes, can you please help me with the syntax for the same?
- 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