java - Mybatis,如何配置才能返回Map<String,List<Person>> 类型的resultMap?
黄舟
黄舟 2017-04-18 09:59:16
0
5
1694

表类似于:
PERSON : ID , NAME , AGE , BIRTHDAY ,STATUS
sql语句类似于:
SELECT * FROM PERSON ORDER BY STATUS

这样,每种STATUS对应了一列PERSON,如何配置Mybatis才能得到Map<String,List<Person>>这样的数据结构?

想象中,配置应该是类似于下边的结构:

<resultMap id="statusMapPerson" type="HashMap<String , List<Person> >">

</resultMap>
黄舟
黄舟

人生最曼妙的风景,竟是内心的淡定与从容!

reply all(5)
左手右手慢动作

The sql statement is similar to:
SELECT * FROM PERSON GROUP BY STATUS
This sql only gets the first item of each STATUS. I don’t know what your application scenario is?

阿神

No way, I can only do it myself. In fact, the maps returned by mybatis are all List<Map<String, Object>>. The key of the Map is column name and the value is column value

刘奇

Search for ResultHandler and see if you can solve it

左手右手慢动作

The result of your group by query is of map type. The usage effect is the same as your string and list style. If you need the kind of result you mentioned, use associate to assemble it yourself. Write an object mapping List<Person>

阿神

map mapping ——
object
-key
-list<String>
First map to the fields of the object
and then convert to map

Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template
About us Disclaimer Sitemap
php.cn:Public welfare online PHP training,Help PHP learners grow quickly!