search

Home  >  Q&A  >  body text

java - Mybatis,如何配置才能返回Map<String,List<Person>> 类型的resultMap?

表类似于:
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>
黄舟黄舟2806 days ago1787

reply all(5)I'll reply

  • ringa_lee

    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?

    reply
    0
  • 阿神

    阿神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

    reply
    0
  • 怪我咯

    怪我咯2017-04-18 10:01:16

    Search for ResultHandler and see if you can solve it

    reply
    0
  • ringa_lee

    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>

    reply
    0
  • 阿神

    阿神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

    reply
    0
  • Cancelreply