表类似于:
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>
ringa_lee2017-04-18 10:01:16
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?
阿神2017-04-18 10:01:16
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
ringa_lee2017-04-18 10:01:16
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>
阿神2017-04-18 10:01:16
map mapping ——
object
-key
-list<String>
First map to the fields of the object
and then convert to map