Returning HashMap of results in MyBatis (rather than List) -
can mybatis return hashmap of results, instead of list? e.g. given table:
foo | bar 1 | 2 | b
and query
select foo, bar foobar
return result of hashmap<string, string> map
map.get(1) == 'a'
, map.get(2) == 'b'
etc?
i've tried variations on following:
<resultmap id="hashmapresult" type="java.util.hashmap"> <id column="foo" /> <result property="bar" column="bar"/> </resultmap> <select id="personstatuses" resultmap="hashmapresult"> select foo, bar foobar </select>
but error: expected 1 result (or null) returned selectone(), found: ...
where tables have primary keys, more useful able results map of pk => row, list of rows.
you have pivot table, let column foo
's rows column, mybatis
can not this, can use sql achieve this(here mysql
solution):
select max(case when foo = 1, bar else null end) `1`, max(case when foo = 2, bar else null end) `2` foobar;
Comments
Post a Comment