for example, I have queries select id, name, age, address from staffs
, instead of having a list of Staff object. I'd prefer to have a list of maps, as
list{
map{
("id", 123),
("name","jackie"),
("address", "canada"),
("age",26)
}
map{
("id", 126),
("name","james"),
("address", "canada"),
("age",27)
}
}
is that possible, and how to do that, if possible? Thanks.
Yes it is possible. You can set resultType
as Hashmap
in your mapper xml file, and it will return a list of maps.
<select id="selectFromStaffs" resultType="Hashmap">
select id, name, age, address from staffs
</select>
And you get it the same way:
...
List listOfMaps = sqlSession.selectList("selectFromStaffs");
...
You can read more about it in the User Guide.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With