我想用番石榴多重地图 https://google.github.io/guava/releases/snapshot/api/docs/com/google/common/collect/Multimap.html as a 结果图 http://www.mybatis.org/mybatis-3/sqlmap-xml.html#Result_Maps with MyBatis http://www.mybatis.org/mybatis-3/,返回一个包含多个一对多条目集合的结果集,但我无法弄清楚其确切的语法。下面是我的表格的示例:
+----+---------+----------+-------------+
| ID | PART_ID | NAME | PART_FAMILY |
+----+---------+----------+-------------+
| 1 | 1 | bush | 300 |
| 2 | 1 | a-bush | 300 |
| 3 | 1 | 300-bush | 300 |
| 4 | 2 | nut | 301 |
+----+---------+----------+-------------+
我想要一个结果集,这样我就有一个 Guava 多重映射,其中 PART_ID 作为键,NAME 和 PART_FAMILY 作为结果。
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)
以下是我的查询:
<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>
我需要以下几点帮助:
- mybatis 可以按照我上面描述的那样在 Guava MultiMap 中返回 resultMap 吗?
- 如果是,您能帮我解决相同的语法吗?
- 如果不是,那么如何获得示例中提到的结果集?
提前致谢!