表类似于:
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>
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 valueSearch 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